Last active
March 13, 2024 08:02
-
-
Save mikejoh/449c50058bbded6c1634b66f45accff3 to your computer and use it in GitHub Desktop.
Revisions
-
mikejoh revised this gist
Jan 16, 2020 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -34,6 +34,7 @@ kubectl label pod POD that=thing Select pods based on selector across all namespaces: ``` kubectl get pods --all-namespaces --selector this=label kubectl get pods --all-namespaces -l this=label ``` Create a single Pod without a Deployment (`--restart=Never`) and a ReplicaSet: ``` -
mikejoh revised this gist
Jan 16, 2020 . No changes.There are no files selected for viewing
-
mikejoh revised this gist
Jan 16, 2020 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -61,4 +61,8 @@ kubectl patch deployment nginx -p '{"spec":{"template":{"spec":{"containers":[{ Sort Kubernetes events on creation timestamp: ``` kubectl get events --sort-by=.metadata.creationTimestamp ``` Output the number of Pods `foo` and skip Pods `bar` that are running per node: ``` kubectl get pods -o wide | grep foo | grep Running | grep -v bar | awk '{print $7}' | sort | uniq -c | sort -nr | wc -l ``` -
mikejoh revised this gist
Sep 24, 2018 . 1 changed file with 64 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +1,64 @@ # kubectl one-liners Enable `kubectl` completion (needs the `bash-completion` package): ``` source <(kubectl completion bash) ``` Dry-run, outputs Service (--expose) and a Deployment in yaml: ``` kubectl run --image=apache \ --port=80 \ --replicas=3 \ --restart='Always' \ --expose \ --requests='cpu=100m,memory=256Mi' \ --limits='cpu=200m,memory=512Mi' \ --labels=app=apache,version=1 \ --dry-run=true \ -o yaml ``` In a running container run `date`: ``` kubectl exec POD -- bash -c "date" kubectl exec POD -- date kubectl exec POD date ``` Remove label `this` from a pod: ``` kubectl label pod POD this- ``` Add label `that=thing` to a pod: ``` kubectl label pod POD that=thing ``` Select pods based on selector across all namespaces: ``` kubectl get pods --all-namespaces --selector this=label ``` Create a single Pod without a Deployment (`--restart=Never`) and a ReplicaSet: ``` kubectl run nginx --image=nginx --restart=Never ``` Create a single Pod with a Deployment (and a ReplicaSet): ``` kubectl run nginx --image=nginx --replicas=1 ``` How the `--restart` flag behaves with `kubectl run`: ``` --restart=Never Creates a single Pod without a Deployment or a ReplicaSet. You can achive this by creating a single Pod manifest and apply it. --restart=OnFailure Creates a Pod and a Job. --restart=Always Default, creates a Deployment and a ReplicaSet object. ``` Copy file to/from a Pod: ``` kubectl cp POD:/path/to/file.txt ./file.txt kubectl $HOME/file.txt POD:/path/to/file.txt ``` Patch a Deployment with a new image: ``` kubectl patch deployment nginx -p '{"spec":{"template":{"spec":{"containers":[{ "name":"nginx", "image":"nginx:1.13.1"}]}}}}' ``` Sort Kubernetes events on creation timestamp: ``` kubectl get events --sort-by=.metadata.creationTimestamp ``` -
mikejoh created this gist
Sep 24, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ kubectl get events --sort-by=.metadata.creationTimestamp