From 3c963586cfa335b185677cd113852bab0c13f1b8 Mon Sep 17 00:00:00 2001 From: Julien Le Coupanec Date: Thu, 1 Mar 2018 16:05:49 -0800 Subject: [PATCH] Kubernetes: improve cheatsheet formatting --- tools/kubernetes.sh | 109 +++++++++++++++++++++++++++++++++----------- 1 file changed, 82 insertions(+), 27 deletions(-) diff --git a/tools/kubernetes.sh b/tools/kubernetes.sh index f9afd6b..0e62252 100644 --- a/tools/kubernetes.sh +++ b/tools/kubernetes.sh @@ -2,39 +2,79 @@ # 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 + +# Setup autocomplete in bash; bash-completion package should be installed first +source <(kubectl completion bash) + +# View Kubernetes config +kubectl config view + +# View specific config items by json path +kubectl config view -o jsonpath='{.users[?(@.name == "k8s")].user.password}' + +# Set credentials for foo.kuberntes.com +kubectl config set-credentials kubeuser/foo.kubernetes.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 + +# List all services in the namespace +kubectl get services + +# List all pods in all namespaces in wide format +kubectl get pods -o wide --all-namespaces + +# List all pods in json (or yaml) format +kubectl get pods -o json + +# Describe resource details (node, pod, svc) +kubectl describe nodes my-node + +# List services sorted by name +kubectl get services --sort-by=.metadata.name + +# List pods sorted by restart count +kubectl get pods --sort-by='.status.containerStatuses[0].restartCount' + +# Rolling update pods for frontend-v1 +kubectl rolling-update frontend-v1 -f frontend-v2.json + +# Scale a replicaset named 'foo' to 3 +kubectl scale --replicas=3 rs/foo + +# Scale a resource specified in "foo.yaml" to 3 +kubectl scale --replicas=3 -f foo.yaml + +# Execute a command in every pod / replica +for i in 0 1; do kubectl exec foo-$i -- sh -c 'echo $(hostname) > /usr/share/nginx/html/index.html'; done + ############################################################################## # 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 + +# Get documentation for pod or service +kubectl explain pods,svc + +# Create resource(s) like pods, services or daemonsets +kubectl create -f ./my-manifest.yaml + +# Apply a configuration to a resource +kubectl apply -f ./my-manifest.yaml + +# Start a single instance of Nginx +kubectl run nginx --image=nginx + +# Create a secret with several keys cat <