You are here: Home » kubernetes » kubectl
Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
kubernetes:kubectl [2022/05/29 08:59] admin kubectl commands |
kubernetes:kubectl [2024/11/22 08:24] (current) admin |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== | + | ====== |
| + | ==Debug running pod without shell access== | ||
| + | < | ||
| + | kubectl debug [existing-pod-name] -it --image alpine --share-processes --copy-to=my-new-debug-pod-name | ||
| + | </ | ||
| - | ==Get secrets with name wildcard== | + | < |
| + | kubectl debug -it [existing-pod-name] --share-processes --image=apko.kontain.me/ | ||
| + | </ | ||
| + | ==Delete terminated pods== | ||
| + | < | ||
| + | #!/bin/sh | ||
| + | for namespace in $(kubectl get ns | awk ' | ||
| + | for pod in $(kubectl get pod -n $namespace --field-selector=status.phase!=Running | grep Terminated | awk ' | ||
| + | kubectl delete pod -n " | ||
| + | done | ||
| + | done | ||
| + | </ | ||
| + | == Get all pods running on a node == | ||
| < | < | ||
| - | kubectl get secret --no-headers=true | awk '/db-container-v8-credentials/{print $1}' | xargs kubectl delete secret | + | function kpodnode() { |
| + | kubectl get pods --all-namespaces -o wide --field-selector spec.nodeName=$1 | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | |||
| + | ====== Secrets ====== | ||
| + | |||
| + | == Create secret manifest from literal == | ||
| + | |||
| + | < | ||
| + | kubectl create secret generic [secret-name] -o yaml --dry-run --from-literal=' | ||
| + | --from-literal=' | ||
| + | </ | ||
| + | |||
| + | == Create secret from file == | ||
| + | |||
| + | < | ||
| + | kubectl create secret generic [secret-name] -o yaml --dry-run --from-file [filepath] | ||
| + | </ | ||
| + | |||
| + | ==Delete all secrets starting with name wildcard== | ||
| + | < | ||
| + | kubectl get secret --no-headers=true | awk '/[secret-partial-name]/{print $1}' | xargs kubectl delete secret | ||
| </ | </ | ||
| + | ====== Configmaps ====== | ||
| + | |||
| + | ==Delete all configmaps with custom label== | ||
| + | < | ||
| + | kubectl get configmap | ||
| + | </ | ||
| + | |||
| + | ====== Wait ====== | ||
| + | |||
| + | == Wait for resource deletion == | ||
| + | |||
| + | < | ||
| + | kubectl wait --for=delete kind/name -n default --timeout=1200s | ||
| + | </ | ||
| + | |||
| + | ====== CRD ====== | ||
| + | |||
| + | == Get an object by querying a specific API version == | ||
| + | |||
| + | < | ||
| + | kubectl get [crd].[version].[group] | ||
| + | </ | ||
| + | |||
| + | Example: | ||
| + | < | ||
| + | kubectl get applications.v1alpha1.argoproj.io | ||
| + | </ | ||
| + | |||
| + | ====== GET ========== | ||
| + | |||
| + | == Get objects sorted by creation date == | ||
| + | |||
| + | < | ||
| + | kubectl get [crd] --sort-by=.metadata.creationTimestamp | ||
| + | </ | ||
| + | |||
| + | ====== LABEL ========== | ||
| + | |||
| + | == Label a node == | ||
| + | |||
| + | < | ||
| + | kubectl label nodes k8-master role=master | ||
| + | </ | ||
| + | |||
| + | ====== Volumes ====== | ||
| + | ==Resize statefulset PVC== | ||
| + | < | ||
| + | # for prometheus volumes, delete operator pod first | ||
| + | k scale deploy monitoring-operator --replicas=0 | ||
| + | kubectl delete sts --cascade=orphan sts_name | ||
| + | # update pvc size | ||
| + | kubectl edit pvc pvc_name | ||
| + | # update pvc size in sts | ||
| + | kubectl -n ns edit sts sts_name | ||
| + | </ | ||