From eeb4ab5b23d34df76b44a4608bf30a1429a7708c Mon Sep 17 00:00:00 2001 From: Daniele Polencic Date: Sat, 24 Feb 2018 17:52:31 +0000 Subject: [PATCH] cheatsheet for Kubernetes --- README.md | 4 +++ tools/kubernetes.sh | 59 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 tools/kubernetes.sh diff --git a/README.md b/README.md index ec2a970..318200b 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,7 @@ You are more than welcome to contribute and build your own cheatsheet for your f * [Docker](tools/docker.sh) * [Nanobox Boxfile](tools/nanobox_boxfile.yml) * [Nanobox CLI](tools/nanobox_cli.sh) +* [Kubernetes](tools/kubernetes.sh) @@ -106,6 +107,9 @@ You are more than welcome to contribute and build your own cheatsheet for your f + + + diff --git a/tools/kubernetes.sh b/tools/kubernetes.sh new file mode 100644 index 0000000..f9afd6b --- /dev/null +++ b/tools/kubernetes.sh @@ -0,0 +1,59 @@ +############################################################################## +# KUBERNETES +############################################################################## + +############################################################################## +# CLIENT CONFIGURATION +############################################################################## + +source <(kubectl completion bash) # Setup autocomplete in bash; bash-completion package should be installed first +kubectl config view # View Kubernetes config +kubectl config view -o jsonpath='{.users[?(@.name == "k8s")].user.password}' # View specific config items by json path +kubectl config set-credentials kubeuser/foo.kubernetes.com \ # Set credentials for foo.kuberntes.com + --username=kubeuser --password=kubepassword + +############################################################################## +# VIEWING, FINDING RESOURCES +############################################################################## + +kubectl get services # List all services in the namespace +kubectl get pods -o wide --all-namespaces # List all pods in all namespaces in wide format +kubectl get pods -o json # List all pods in json (or yaml) format +kubectl describe nodes my-node # Describe resource details (node, pod, svc) +kubectl get services --sort-by=.metadata.name # List services sorted by name +kubectl get pods --sort-by='.status.containerStatuses[0].restartCount' # List pods sorted by restart count +kubectl rolling-update frontend-v1 -f frontend-v2.json # Rolling update pods for frontend-v1 +kubectl scale --replicas=3 rs/foo # Scale a replicaset named 'foo' to 3 +kubectl scale --replicas=3 -f foo.yaml # Scale a resource specified in "foo.yaml" to 3 +for i in 0 1; do kubectl exec foo-$i -- sh -c 'echo $(hostname) > /usr/share/nginx/html/index.html'; done # Execute a command in every pod / replica + +############################################################################## +# MANAGE RESOURCES +############################################################################## + +kubectl explain pods,svc # Get documentation for pod or service +kubectl create -f ./my-manifest.yaml # Create resource(s) like pods, services or daemonsets +kubectl apply -f ./my-manifest.yaml # Apply a configuration to a resource +kubectl run nginx --image=nginx # Start a single instance of Nginx +cat <