- https://prefetch.net/blog/2019/10/16/the-beginners-guide-to-creating-kubernetes-manifests/
- https://gist.github.com/constantlycoding/220f0dcb4aef8b0a14d4f336f0b102b1
- https://kubernetes.io/docs/user-guide/kubectl-cheatsheet/
- https://learnk8s.io/blog/kubectl-productivity/
- https://medium.com/faun/kubectl-commands-cheatsheet-43ce8f13adfb
- https://gist.github.com/so0k/42313dbb3b547a0f51a547bb968696ba
- https://speakerdeck.com/so0k/kubectl-tips-and-tricks
- https://github.com/dennyzhang/cheatsheet-kubernetes-A4
- https://medium.com/bitnami-perspectives/imperative-declarative-and-a-few-kubectl-tricks-9d6deabdde
- http://blog.kubernetes.io/2015/10/some-things-you-didnt-know-about-kubectl_28.html
- https://medium.com/free-code-camp/how-to-set-up-a-serious-kubernetes-terminal-dd07cab51cd4
- https://github.com/aylei/kubectl-debug
- https://kubernetes.io/docs/tasks/manage-kubernetes-objects/imperative-command/
- https://medium.com/bitnami-perspectives/imperative-declarative-and-a-few-kubectl-tricks-9d6deabdde
- https://blog.heptio.com/using-kubectl-to-jumpstart-a-yaml-file-heptioprotip-6f5b8a63a3ea
kubectl run my-cool-app —-image=me/my-cool-app:v1 \
-o yaml --dry-run > my-cool-app.yaml
kubectl run kuard --generator=run-pod/v1 --replicas=2 --image=gcr.io/kuar-demo/kuard-amd64:1 --dry-run -o yaml
kubectl create configmap ip-masq-agent --from-file=config --namespace=kube-system --dry-run -o yaml > ip-masq-agent.yaml
kubectl run kuard --generator=run-pod/v1 --replicas=2 --image=gcr.io/kuar-demo/kuard-amd64:1
kubectl port-forward kuard 8080:8080
kubectl expose deployment kuard --type=LoadBalancer --port=80 --target-port=8080
get current context: kubectl config view -o=jsonpath='{.current-context}'
get all contexts: kubectl config get-contexts -o=name | sort -n
get namesapce: kubectl get namespaces -o=jsonpath='{range .items[*].metadata.name}{@}{"\n"}{end}'
kubectl config use-context <cluster_name_in_kubeconfig>
kubectl --context <context>
## set the namespace for the current context
kubectl config set-context gke_sandbox-co_us-west1-a_cka --namespace=kube-system
kubectl config set-context --current --namespace=kube-system
# Print the supported API versions on the server, in the form of "group/version"
k api-versions
# for each "group/version" in the output above except for "api/v1"
kubectl get --raw /apis/group/version | jq -r '.resources[].kind'
echo $(kubectl get secret/terraform -o jsonpath="{.data['terraform\.json']}" | base64 --decode)
- https://gist.github.com/so0k/42313dbb3b547a0f51a547bb968696ba
- https://kubernetes.io/docs/tasks/access-application-cluster/list-all-running-container-images/
grace=$(kubectl get po cassandra-0 -o=jsonpath=‘{.spec.terminationGracePeriodSeconds}’)
grace=$(kubectl get sts -l component=elasticsearch,role=data -o jsonpath='{..terminationGracePeriodSeconds}'
kubectl get svc -l component=elasticsearch,role=client -o jsonpath='{..ip}'
kubectl get pods -o jsonpath="{..image}"
kubectl get pods -o jsonpath="{.items[*].spec.containers[*].image}"
kubectl get pods -o jsonpath='{.items[*].status.podIP}'
kubectl get pods -o jsonpath='{range .items[*]}{"\n"}{.metadata.name}{":\t"}{range .spec.containers[*]}{.image}{", "}{end}{end}'
kubectl get pods -o go-template --template="{{range .items}}{{range .spec.containers}}{{.image}} {{end}}{{end}}"
kubectl get nodes -o jsonpath='{.items[*].spec.podCIDR}' | tr " " "\n"
kubectl get nodes -o json | jq '.items[] | .spec'
kubectl get no -o go-template='{{range .items}}{{.spec.podCIDR}}{{"\n"}}{{end}}'
kubectl get po -o wide --sort-by=.spec.nodeName
kubectl get pv --sort-by=.spec.capacity.storage -o=custom-columns="NAME:.metadata.name,CAPACITY:.spec.capacity.storage"
EXT_IP="$(kubectl get svc hello-server -o=jsonpath='{.status.loadBalancer.ingress[0].ip}')"
EXT_PORT=$(kubectl --namespace default get service hello-server -o=jsonpath='{.spec.ports[0].port}')
echo "$EXT_IP:$EXT_PORT"
[ "$(curl -s -o /dev/null -w '%{http_code}' "$EXT_IP:$EXT_PORT"/)" -eq 200 ] || exit 1
kubectl get pods -o jsonpath --template='{range .items[*]}{.met
ata.name}{"\t"}{"\t"}{.spec.containers[0].image}{"\n"}{end}'
kubectl rollout pause deployment/hello
kubectl rollout status deployment/hello
# check the versions on pods
kubectl get pods -o jsonpath --template='{range .items[*]}{.metadata.name}{"\t"}{"\t"}{.spec.containers[0].image}{"\n"}{end}'
kubectl rollout resume deployment/hello
# roll back
kubectl rollout undo deployment/hello
# cpu
kubectl top pods -A | sort --reverse --key 3 --numeric
# memory
kubectl top pods -A | sort --reverse --key 4 --numeric
# top 1
kubectl top pod | grep -v NAME | sort -k 3 -nr | awk -F ' ' 'NR==1{print $1}'
## debug pod
apiVersion: v1 kind: Pod metadata: name: bb namespace: debug labels: app: bb spec: containers:
- image: docker.io/library/busybox:1.28.4
name: bb
command:
- sh
- -c
- tail -f /dev/null volumeMounts:
- mountPath: /rootfs name: host volumes:
- name: host hostPath: path: /