Skip to content

Instantly share code, notes, and snippets.

@geunho
Last active March 29, 2023 11:36
Show Gist options
  • Save geunho/ca30d9ba8447e50ca93e825c9c99cbff to your computer and use it in GitHub Desktop.
Save geunho/ca30d9ba8447e50ca93e825c9c99cbff to your computer and use it in GitHub Desktop.
kubectl cheat sheet ๐Ÿ’ซ
# ์ด๋ฏธ์ง€ ํ™•์ธ์„ ์œ„ํ•ด ์ž„์‹œ๋กœ /bin/bash pod ๋„์šฐ๊ธฐ
kubectl run $POD_NAME --rm -i --tty --restart=Never --image=$IMAGE:$TAG --command -- /bin/bash
# pod ์ƒํƒœ ๋ณ€๊ฒฝ์‹œ ์ถœ๋ ฅํ•˜๊ธฐ - OOMKill ๋“ฑ ํ™•์ธ์‹œ ์‚ฌ์šฉ
kubectl get pod -w
# pvc ์šฉ๋Ÿ‰ ์ฆ์„ค (๋ณ€๊ฒฝ ์ €์žฅ ํ›„ ๋ฌผ๊ณ ์žˆ๋Š” pod ์žฌ์‹œ์ž‘ํ•ด์•ผํ•จ)
kubectl edit pvc $PVC_NAME
# statefulset pod ์žฌ์‹œ์ž‘
kc scale sts/mysql --replicas=0
kc scale sts/mysql --replicas=1
# ํด๋Ÿฌ์Šคํ„ฐ ๋‚ด ๊ตฌ๋™์ค‘์ธ pod์˜ ๋ชจ๋“  ์ด๋ฏธ์ง€ ๋ฆฌ์ŠคํŒ…
# https://kubernetes.io/ko/docs/tasks/access-application-cluster/list-all-running-container-images/
kubectl get pods -o jsonpath="{.items[*].spec.containers[*].image}" | tr -s '[[:space:]]' '\n'
# namespace, pod ์ด๋ฆ„๊ณผ ์ด๋ฏธ์ง€๋ฅผ ๋ฆฌ์ŠคํŒ…
kubectl get pods -o jsonpath='{range .items[*]}{@.metadata.namespace}{"\t"}{@.metadata.name}{"\t"}{@.spec.containers[*].image}{"\n"}{end}'
# deploy image ์กฐํšŒ
kubectl get deploy $DEPLOY_NAME -o=jsonpath='{$.spec.template.spec.containers[:1].image}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment