🪴 Pauloriculture

Search

Search IconIcon to open search

[Basic] Kubernetes Commands (KR)

Last updated Jul 17, 2023 - Edit Source

# OS

Mac OS Apple M1 Pro 13.4.1

# reference

https://kubernetes.io/docs/reference/kubectl/cheatsheet/

# install requirements

1
2
brew install kubectl
brew install helm

# for cluster

1
2
brew install kind
brew install minikube # you can choose one of them

# deploy cluster

# minikube

1
minikube start --cpus {n} --memory {m} # n = number of cores / m = size of memory (mb)

# kind

1
kind create cluster --image kindest/node:v1.21.1 # check version

# load local docker image to cluster

# minikube

1
2
3
4
minikube docker-env # To point your shell to minikube's docker-daemon, run:
eval $(minikube -p minikube docker-env) # from then, this shell can share the image you want
docker build {your_image} # execute on the same shell
minikube image ls --format table # check if the image is contained

# kind

1
kind load docker-image {your_image}

# kubectl

# create namespace

1
kubectl create namespace {your_namespace}

# move namespace

1
2
kubectl config use-context {your_namespace} # temporarily
kubectl config set-context --curent --namespace={your_namespace} # permanently

# create objects

1
kubectl apply -f {yaml_directory}

# get resource

1
2
3
4
5
6
kubectl get all # see all resources
kubectl get pod --sort-by=.metadata.name # pods / sort by name
kubectl get svc # services
kubectl get namespace
kubectl get deployment
kubectl get secret

# Describe commands with verbose output

1
kubectl describe pod {your_pod}

# get pod logs

1
kubectl logs {your_pod} -c {container_name} # with -c option, you can get logs of specific container.

# access into pod shell

1
kubectl exec -it {pod_name} -- /bin/bash # it can be /bin/sh

# port forwarding

1
kubectl port-forward svc/{service_name} {localhost_port}:{service_port} --namespace {your_namespace}

# helm chart

# create helm chart with template

1
helm create {app_name}

# helm lint before deployment

1
helm lint

# helm get yaml file

1
helm template {chart_directory} --debug # --debug option will show line number with error message if it doesn't work properly

# helm deploy chart

1
helm install {app_name} {chart_directory} --values {custom_values_file} --namespace {your_namespace} {--create-namespace} # deploy helm chart, --create-namespace option creates namespace if it doesn't exist

# helm upgrade chart

1
helm upgrade {app_name} {chart_directory} --values {custom_values_file} --namespace {your_namespace}

# helm delete chart

1
helm uninstall {app_name}