k get configmap -n kube-system -l "OWNER=TILLER"
k get configmap -n kube-system -o yaml scout-post-director.v14
kubectl get configmap -n kube-system my-release.v1 -o=jsonpath='{.data.release}' > release-encoded
cat base64|base64 -D|gzip -cd>release-decoded
Last active
March 31, 2021 19:31
-
-
Save ps-przemekaugustyn/6e484fe1adff3fa2639bb38ca1c2f3af to your computer and use it in GitHub Desktop.
K8s cheatsheet
k=kubectl
# list node labels
k get nodes --show-labels|grep something
# overwrite label
k label nodes --overwrite ip-aaa.ec2.internal kops.k8s.io/instancegroup=nodes
# remove taint
k taint node ip-aaa.internal dedicated-
k cluster-info
k get ns
k top node
k top node --heapster-namespace='default'
k api-resources
# export last 1h to file
k logs --timestamps --since=1h myservice-deployment-8bb98f7dd-2znnf> myservice-1h.log
# since time
k logs --timestamps -n myspace -c containername mydeployment-5bff479bfd-565jr --since-time=2020-08-23T13:30:00Z
# logs of deployment (seems to report more than it should? bug? labels instead of deployment name?)
k logs -f deployments/mydeployment -n myspace
k logs -n myspace deployments/mydeployment --all-containers=true
# tail and follow
k logs -f --tail 100 -n myspace myservice-deployment-7c6b98b7ff-46cdw
# describe pod
k describe pod -n myspace mydeployment-7cc495dbbd-2m6ll
# pods that are in a failed state (evicted)
kubectl -n myspace delete pods -l app.kubernetes.io/name=mylabel --field-selector=status.phase=Failed
# top pods
k top pod -n myspace -l app.kubernetes.io/name=mylabel
# list pods that are in status.phase (Running/Failed)
k get pods -n myspace -l app=myapp-label --field-selector status.phase=Running -o wide --no-headers
k get pods -n myspace -l app=myapp-label --field-selector status.phase!=Running -o wide --no-headers
# sort by restarts [:1] <- first element of an array
k get pods -n myspace --field-selector status.phase=Running --sort-by="{.status.containerStatuses[:1].restartCount}"
# reverse order by restarts
k get pods -n myspace --field-selector status.phase=Running --sort-by="{.status.containerStatuses[:1].restartCount}"|tac
# list env variables of pod
k exec -it -n myspace mypod-5d95ccfc58-7vnwd -- env
# list all deployments (all namespaces)
k get deployments --all-namespaces
# list replicasets
k get rs -n myspace
# scale replicas
k scale deployment/mydeployment -n myspace --replicas=10
k describe svc -n myspace my-service
k get endpoints -n monitoring --v=0
k get endpoints -n monitoring -o json
k get events -n myspace
k get events --sort-by=.metadata.creationTimestamp
k get configmap --namespace monitoring
k get secrets -n myspace -o yaml
k get secret mysecret -n myspace -o jsonpath='{ .data.connection-string }' | base64 -d
# run temporary pod on cluster
kubectl run tmp-shell --rm -i --tty --image centos -- /bin/bash
# terminal to docker VM on mac
docker run -it --rm --privileged --pid=host justincormack/nsenter1
# list docker image for pods
kubectl get pods -n premo -o jsonpath="{..imageID}"
# list node taints
k get nodes -o jsonpath='{range .items[*]}{.metadata.name}{.spec.taints}{"\n"}'
# list node status
k get nodes -o jsonpath='{range .items[*]}{.status}{"\n"}'
# list external ip addresses of worker nodes
k get nodes --selector=kubernetes.io/role!=master -o jsonpath='{.items[*].status.addresses[?(@.type=="ExternalIP")].address}' | awk '{split($0, a, " "); for(key in a){ print a[key]}}'
# pretty print custom jsonpath from pod manifest
k get pod -n premo -o jsonpath="{.status.containerStatuses}" premo-nightmare-77b658986b-trntr|python -m json.tool
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment