From 00918e7080a71ed12fd6abf2e7b136c2fb22ab78 Mon Sep 17 00:00:00 2001 From: Mihir Date: Sat, 18 Jul 2020 15:24:42 -0700 Subject: [PATCH] refactor(docs): convert .sh file to .md --- tools/kubernetes.md | 179 ++++++++++++++++++++++++++++++++++++++++++++ tools/kubernetes.sh | 137 --------------------------------- 2 files changed, 179 insertions(+), 137 deletions(-) create mode 100644 tools/kubernetes.md delete mode 100644 tools/kubernetes.sh diff --git a/tools/kubernetes.md b/tools/kubernetes.md new file mode 100644 index 0000000..f453c62 --- /dev/null +++ b/tools/kubernetes.md @@ -0,0 +1,179 @@ +# Kubernetes + +* PDF: https://sematext.com/kubernetes-cheat-sheet/ +* WEBSITE: https://kubernetes.io/ +* DOCUMENTATION: https://kubernetes.io/docs/home + +## Client Configuration + +* 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 +``` + +* Set active namespace +``` +kubectl config set-context --current --namespace=namespace_name +``` + +## Viewing, Finding resources + +* 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 + +* 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 < /usr/share/nginx/html/index.html'; done - - -############################################################################## -# MANAGE RESOURCES -############################################################################## - - -# 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 <