Search
Search Icon Icon to open search [Basic] Kubernetes Commands (KR) Last updated
Jul 17, 2023
- Edit Source
# OSMac OS Apple M1 Pro 13.4.1
# referencehttps://kubernetes.io/docs/reference/kubectl/cheatsheet/
# install requirements1
2
brew install kubectl
brew install helm
# for cluster1
2
brew install kind
brew install minikube # you can choose one of them
# deploy cluster# minikube1
minikube start --cpus {n} --memory {m} # n = number of cores / m = size of memory (mb)
# kind1
kind create cluster --image kindest/node:v1.21.1 # check version
# load local docker image to cluster# minikube1
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
# kind1
kind load docker-image {your_image}
# kubectl# create namespace1
kubectl create namespace {your_namespace}
# move namespace1
2
kubectl config use-context {your_namespace} # temporarily
kubectl config set-context --curent --namespace={your_namespace} # permanently
# create objects1
kubectl apply -f {yaml_directory}
# get resource1
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 output1
kubectl describe pod {your_pod}
# get pod logs1
kubectl logs {your_pod} -c {container_name} # with -c option, you can get logs of specific container.
# access into pod shell1
kubectl exec -it {pod_name} -- /bin/bash # it can be /bin/sh
# port forwarding1
kubectl port-forward svc/{service_name} {localhost_port}:{service_port} --namespace {your_namespace}
# helm chart# create helm chart with template# helm lint before deployment# helm get yaml file1
helm template {chart_directory} --debug # --debug option will show line number with error message if it doesn't work properly
# helm deploy chart1
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 chart1
helm upgrade {app_name} {chart_directory} --values {custom_values_file} --namespace {your_namespace}
# helm delete chart1
helm uninstall {app_name}