• Stars
    star
    1,851
  • Rank 25,055 (Top 0.5 %)
  • Language
    Shell
  • Created almost 7 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿ“– Kubernetes CheatSheets In A4

1 Kubectl Kubernetes CheatSheet

linkedin
github
slack


PRs Welcome

File me Issues or star this repo.

1.1 Common Commands

NameCommand
Run curl test temporarilykubectl run --generator=run-pod/v1 --rm mytest --image=yauritux/busybox-curl -it
Run wget test temporarilykubectl run --generator=run-pod/v1 --rm mytest --image=busybox -it wget
Run nginx deployment with 2 replicaskubectl run my-nginx --image=nginx --replicas=2 --port=80
Run nginx pod and expose itkubectl run my-nginx --restart=Never --image=nginx --port=80 --expose
Run nginx deployment and expose itkubectl run my-nginx --image=nginx --port=80 --expose
List authenticated contextskubectl config get-contexts, ~/.kube/config
Set namespace preferencekubectl config set-context <context_name> --namespace=<ns_name>
List pods with nodes infokubectl get pod -o wide
List everythingkubectl get all --all-namespaces
Get all serviceskubectl get service --all-namespaces
Get all deploymentskubectl get deployments --all-namespaces
Show nodes with labelskubectl get nodes --show-labels
Get resources with json outputkubectl get pods --all-namespaces -o json
Validate yaml file with dry runkubectl create --dry-run --validate -f pod-dummy.yaml
Start a temporary pod for testingkubectl run --rm -i -t --image=alpine test-$RANDOM -- sh
kubectl run shell commandkubectl exec -it mytest -- ls -l /etc/hosts
Get system conf via configmapkubectl -n kube-system get cm kubeadm-config -o yaml
Get deployment yamlkubectl -n denny-websites get deployment mysql -o yaml
Explain resourcekubectl explain pods, kubectl explain svc
Watch podskubectl get pods -n wordpress --watch
Query healthcheck endpointcurl -L http://127.0.0.1:10250/healthz
Open a bash terminal in a podkubectl exec -it storage sh
Check pod environment variableskubectl exec redis-master-ft9ex env
Enable kubectl shell autocompletionecho "source <(kubectl completion bash)" >>~/.bashrc, and reload
Use minikube dockerd in your laptopeval $(minikube docker-env), No need to push docker hub any more
Kubectl apply a folder of yaml fileskubectl apply -R -f .
Get services sorted by namekubectl get services โ€“sort-by=.metadata.name
Get pods sorted by restart countkubectl get pods โ€“sort-by=โ€™.status.containerStatuses[0].restartCountโ€™
List pods and imageskubectl get pods -o=โ€™custom-columns=PODS:.metadata.name,Images:.spec.containers[*].imageโ€™
List all container imageslist-all-images.sh
kubeconfig skip tls verificationskip-tls-verify.md
Ubuntu install kubectl=โ€deb https://apt.kubernetes.io/ kubernetes-xenial mainโ€=
ReferenceGitHub: kubernetes releases
Referenceminikube cheatsheet, docker cheatsheet, OpenShift CheatSheet

1.2 Check Performance

NameCommand
Get node resource usagekubectl top node
Get pod resource usagekubectl top pod
Get resource usage for a given podkubectl top <podname> --containers
List resource utilization for all containerskubectl top pod --all-namespaces --containers=true

1.3 Resources Deletion

NameCommand
Delete podkubectl delete pod/<pod-name> -n <my-namespace>
Delete pod by forcekubectl delete pod/<pod-name> --grace-period=0 --force
Delete pods by labelskubectl delete pod -l env=test
Delete deployments by labelskubectl delete deployment -l app=wordpress
Delete all resources filtered by labelskubectl delete pods,services -l name=myLabel
Delete resources under a namespacekubectl -n my-ns delete po,svc --all
Delete persist volumes by labelskubectl delete pvc -l app=wordpress
Delete state fulset only (not pods)kubectl delete sts/<stateful_set_name> --cascade=false

1.4 Log & Conf Files

NameComment
Config folder/etc/kubernetes/
Certificate files/etc/kubernetes/pki/
Credentials to API server/etc/kubernetes/kubelet.conf
Superuser credentials/etc/kubernetes/admin.conf
kubectl config file~/.kube/config
Kubernetes working dir/var/lib/kubelet/
Docker working dir/var/lib/docker/, /var/log/containers/
Etcd working dir/var/lib/etcd/
Network cni/etc/cni/net.d/
Log files/var/log/pods/
log in worker node/var/log/kubelet.log, /var/log/kube-proxy.log
log in master nodekube-apiserver.log, kube-scheduler.log, kube-controller-manager.log
Env/etc/systemd/system/kubelet.service.d/10-kubeadm.conf
Envexport KUBECONFIG=/etc/kubernetes/admin.conf

1.5 Pod

NameCommand
List all podskubectl get pods
List pods for all namespacekubectl get pods --all-namespaces
List all critical podskubectl get -n kube-system pods -a
List pods with more infokubectl get pod -o wide, kubectl get pod/<pod-name> -o yaml
Get pod infokubectl describe pod/srv-mysql-server
List all pods with labelskubectl get pods --show-labels
List all unhealthy podskubectl get pods โ€“field-selector=status.phase!=Running โ€“all-namespaces
List running podskubectl get pods โ€“field-selector=status.phase=Running
Get Pod initContainer statuskubectl get pod --template '{{.status.initContainerStatuses}}' <pod-name>
kubectl run commandkubectl exec -it -n โ€œ$nsโ€ โ€œ$podnameโ€ โ€“ sh -c โ€œecho $msg >>/dev/err.logโ€
Watch podskubectl get pods -n wordpress --watch
Get pod by selectorkubectl get pods โ€“selector=โ€app=syslogโ€ -o jsonpath=โ€™{.items[*].metadata.name}โ€™
List pods and imageskubectl get pods -o=โ€™custom-columns=PODS:.metadata.name,Images:.spec.containers[*].imageโ€™
List pods and containers-o=โ€™custom-columns=PODS:.metadata.name,CONTAINERS:.spec.containers[*].nameโ€™
ReferenceLink: kubernetes yaml templates

1.6 Label & Annotation

NameCommand
Filter pods by labelkubectl get pods -l owner=denny
Manually add label to a podkubectl label pods dummy-input owner=denny
Remove labelkubectl label pods dummy-input owner-
Manually add annotation to a podkubectl annotate pods dummy-input my-url=https://dennyzhang.com

1.7 Deployment & Scale

NameCommand
Scale outkubectl scale --replicas=3 deployment/nginx-app
online rolling upgradekubectl rollout app-v1 app-v2 --image=img:v2
Roll backupkubectl rollout app-v1 app-v2 --rollback
List rolloutkubectl get rs
Check update statuskubectl rollout status deployment/nginx-app
Check update historykubectl rollout history deployment/nginx-app
Pause/Resumekubectl rollout pause deployment/nginx-deployment, resume
Rollback to previous versionkubectl rollout undo deployment/nginx-deployment
ReferenceLink: kubernetes yaml templates, Link: Pausing and Resuming a Deployment

1.8 Quota & Limits & Resource

NameCommand
List Resource Quotakubectl get resourcequota
List Limit Rangekubectl get limitrange
Customize resource definitionkubectl set resources deployment nginx -c=nginx --limits=cpu=200m
Customize resource definitionkubectl set resources deployment nginx -c=nginx --limits=memory=512Mi
ReferenceLink: kubernetes yaml templates

1.9 Service

NameCommand
List all serviceskubectl get services
List service endpointskubectl get endpoints
Get service detailkubectl get service nginx-service -o yaml
Get service cluster ipkubectl get service nginx-service -o go-template=โ€™{{.spec.clusterIP}}โ€™
Get service cluster portkubectl get service nginx-service -o go-template=โ€™{{(index .spec.ports 0).port}}โ€™
Expose deployment as lb servicekubectl expose deployment/my-app --type=LoadBalancer --name=my-service
Expose service as lb servicekubectl expose service/wordpress-1-svc --type=LoadBalancer --name=ns1
ReferenceLink: kubernetes yaml templates

1.10 Secrets

NameCommand
List secretskubectl get secrets --all-namespaces
Generate secretecho -n 'mypasswd', then redirect to base64 --decode
Get secretkubectl get secret denny-cluster-kubeconfig
Get a specific field of a secretkubectl get secret denny-cluster-kubeconfig -o jsonpath=โ€{.data.value}โ€
Create secret from cfg filekubectl create secret generic db-user-pass โ€“from-file=./username.txt
ReferenceLink: kubernetes yaml templates, Link: Secrets

1.11 StatefulSet

NameCommand
List statefulsetkubectl get sts
Delete statefulset only (not pods)kubectl delete sts/<stateful_set_name> --cascade=false
Scale statefulsetkubectl scale sts/<stateful_set_name> --replicas=5
ReferenceLink: kubernetes yaml templates

1.12 Volumes & Volume Claims

NameCommand
List storage classkubectl get storageclass
Check the mounted volumeskubectl exec storage ls /data
Check persist volumekubectl describe pv/pv0001
Copy local file to podkubectl cp /tmp/my <some-namespace>/<some-pod>:/tmp/server
Copy pod file to localkubectl cp <some-namespace>/<some-pod>:/tmp/server /tmp/my
ReferenceLink: kubernetes yaml templates

1.13 Events & Metrics

NameCommand
View all eventskubectl get events --all-namespaces
List Events sorted by timestampkubectl get events โ€“sort-by=.metadata.creationTimestamp

1.14 Node Maintenance

NameCommand
Mark node as unschedulablekubectl cordon $NODE_NAME
Mark node as schedulablekubectl uncordon $NODE_NAME
Drain node in preparation for maintenancekubectl drain $NODE_NAME

1.15 Namespace & Security

NameCommand
List authenticated contextskubectl config get-contexts, ~/.kube/config
Set namespace preferencekubectl config set-context <context_name> --namespace=<ns_name>
Switch contextkubectl config use-context <context_name>
Load context from config filekubectl get cs --kubeconfig kube_config.yml
Delete the specified contextkubectl config delete-context <context_name>
List all namespaces definedkubectl get namespaces
List certificateskubectl get csr
Check user privilegekubectl โ€“as=system:serviceaccount:ns-denny:test-privileged-sa -n ns-denny auth can-i use pods/list
Check user privilegekubectl auth can-i use pods/list
ReferenceLink: kubernetes yaml templates

1.16 Network

NameCommand
Temporarily add a port-forwardingkubectl port-forward redis-134 6379:6379
Add port-forwarding for deploymentkubectl port-forward deployment/redis-master 6379:6379
Add port-forwarding for replicasetkubectl port-forward rs/redis-master 6379:6379
Add port-forwarding for servicekubectl port-forward svc/redis-master 6379:6379
Get network policykubectl get NetworkPolicy
Get ingress controllerkubectl get ingress
Get ingress classeskubectl get ingressclasses

1.17 Patch

NameSummary
Patch service to loadbalancerkubectl patch svc $svc_name -p โ€˜{โ€œspecโ€: {โ€œtypeโ€: โ€œLoadBalancerโ€}}โ€™

1.18 Extenstions

NameSummary
Enumerates the resource types availablekubectl api-resources
List api groupkubectl api-versions
List all CRDkubectl get crd
List storageclasskubectl get storageclass

1.19 Components & Services

1.19.1 Services on Master Nodes

NameSummary
kube-apiserverAPI gateway. Exposes the Kubernetes API from master nodes
etcdreliable data store for all k8s cluster data
kube-schedulerschedule pods to run on selected nodes
kube-controller-managerReconcile the states. node/replication/endpoints/token controller and service account, etc
cloud-controller-manager

1.19.2 Services on Worker Nodes

NameSummary
kubeletA node agent makes sure that containers are running in a pod
kube-proxyManage network connectivity to the containers. e.g, iptable, ipvs
Container RuntimeKubernetes supported runtimes: dockerd, cri-o, runc and any OCI runtime-spec implementation.

1.19.3 Addons: pods and services that implement cluster features

NameSummary
DNSserves DNS records for Kubernetes services
Web UIa general purpose, web-based UI for Kubernetes clusters
Container Resource Monitoringcollect, store and serve container metrics
Cluster-level Loggingsave container logs to a central log store with search/browsing interface

1.19.4 Tools

NameSummary
kubectlthe command line util to talk to k8s cluster
kubeadmthe command to bootstrap the cluster
kubefedthe command line to control a Kubernetes Cluster Federation
Kubernetes ComponentsLink: Kubernetes Components

1.20 More Resources

License: Code is licensed under MIT License.

https://kubernetes.io/docs/reference/kubectl/cheatsheet/

https://codefresh.io/kubernetes-guides/kubernetes-cheat-sheet/

linkedin github slack

More Repositories

1

cheatsheet.dennyzhang.com

Apply best practices via CheatSheets
Shell
649
star
2

kubernetes-yaml-templates

Kubernetes Yaml Templates
594
star
3

cheatsheet-jenkins-groovy-A4

๐Ÿ“– Groovy CheatSheet For Jenkins Usage In A4
Groovy
325
star
4

challenges-kubernetes

โ˜๏ธ Challenges Your Kubernetes Skills And Knowledge
Shell
230
star
5

devops_public

๐ŸŽฉ DevOps Scripts
Shell
179
star
6

cheatsheet-gcp-A4

โ˜๏ธ GCP gcloud, gsutil, etc.
110
star
7

cheatsheet-python-A4

๐Ÿ“– Advanced Python Syntax In A4
Python
100
star
8

code.dennyzhang.com

โ“ Algorithms & Coding Problems
CSS
95
star
9

cheatsheet-docker-A4

๐Ÿ“– Docker CheatSheets In A4
Dockerfile
90
star
10

monitor-docker-slack

โฐ Get Slack Notifications, When Containers Run Into Issues
Python
71
star
11

challenges-cloudformation-jenkins

๐Ÿซ Challenges Your AWS And Cloudformation Skills By Solving Real Questions.
Shell
60
star
12

cheatsheet-golang-A4

๐Ÿ“– Advanced Golang Syntax In A4
Go
56
star
13

prepare-k8s-cka

๐Ÿ“– Preparation For Kubernetes CKA/CKAD Exam
51
star
14

cheatsheet-aws-A4

โ˜๏ธ AWS CheatSheets In A4
48
star
15

cheatsheet-paper-A4

https://cheatsheet.dennyzhang.com/cheatsheet-paper-A4
46
star
16

Denny-s-emacs-configuration

๐Ÿค– Emacs shapes me to be a better programmer
Emacs Lisp
41
star
17

kubernetes-scripts

Handy kubernetes scripts for common scenarios
Shell
37
star
18

challenges-chef

๐Ÿ“– Challenges Your Chef Skills By Solving Real Questions.
Ruby
26
star
19

cheatsheet-git-A4

CheatSheet For Git & GitHub
25
star
20

developer-free-saas

๐Ÿ•ธ๏ธ A curated list Of Free Web-based Tools For Developers
Shell
23
star
21

devops_jenkins

๐Ÿค– VisualOps via Jenkins jobs
21
star
22

architect.dennyzhang.com

โ˜๏ธ Learn system design in a solid way
Shell
21
star
23

cheatsheet-tmux-A4

tmux/tmate Usage in A4
20
star
24

cheatsheet-vim-A4

Vim usage and personal knowledge base
18
star
25

cheatsheet-pks-A4

CheatSheet For PKS: Pivotal Kubernetes Service
Shell
16
star
26

popular-github-template

๐Ÿ“— Repo Template: Make Your GitHub Repos More Popular
16
star
27

cheatsheet-shell-A4

๐Ÿซ Examine your shell skills
Shell
16
star
28

xiaozibao

Your personal magzine, adjusted by your taste.
Objective-C
13
star
29

python-selenium

Use Python Selenium For GUI Automation Test
Python
11
star
30

cheatsheet-bosh-A4

๐Ÿ“– CheatSheet For CloudFoundry Bosh
Shell
10
star
31

remote-commands-servers

๐Ÿ‘ช Run remote ssh commands on multiple servers
Python
9
star
32

monitoring

Checks for various monitoring
Shell
9
star
33

chatops_slack

๐Ÿš€ Python Slack ChatOps
Python
7
star
34

elasticsearch-cli-tool

๐Ÿช CLI tools for ealsticsearch
Python
6
star
35

developer-technical-selling

๐Ÿ’ต Do a better technical selling as a developer
5
star
36

linkedin-grow-influence

๐Ÿ”Œ How To Improve Professional Influence In Linkedin
5
star
37

challenges-k8s-monitoring

Notes for deep dive into Kubernetes monitoring
5
star
38

cheatsheet-emacs-A4

๐Ÿ“– Emacs lisp cheatsheet
Emacs Lisp
5
star
39

challenges-aws-ecs

โœ๏ธ Case study using AWS ECS to setup personal wordpress
PHP
5
star
40

challenges-k8s-crd

Kubernets CRD: extend k8s resource
Dockerfile
4
star
41

cheatsheet-ruby-A4

๐Ÿ“– Advanced Ruby Syntax In A4
4
star
42

detect_suspicious_process

Detect suspicious process
Python
4
star
43

directory-cli-tool

๐Ÿ“ CLI tools for directories
Shell
3
star
44

python-hosts-tool

๐Ÿ“ Manage /etc/hosts in an organized way by Python
Python
3
star
45

code-with-docker

Use docker to write code in different languages
Shell
3
star
46

www.dennyzhang.com

Personal blog: DevOps, Cloud, Life
Shell
3
star
47

challenges-k8s-logging

Notes for deep dive into Kubernetes logging
3
star
48

challenges-k8s-storage

Notes for deep dive into Kubernetes storage
3
star
49

maintain-github-repos

๐Ÿ‘ช KnowledgeBase: Grow Influence From Maintaining Github Projects
3
star
50

maintain-it-blog

๐Ÿ“š Be a better IT Blogger
3
star
51

chef_community_cookbooks

๐Ÿ– Chef cookbooks for devops
Python
3
star
52

nmap-scan-docker

nmap network scan via docker
Python
3
star
53

shadowsocks-vpn-docker

๐Ÿ—๏ธ Docker shadowsocks VPN
Shell
2
star
54

dennytest

Github Repo to host various test scripts
Go
2
star
55

jenkins_image

๐Ÿ’‚โ€โ™‚๏ธ Jenkins Docker Image
Shell
2
star
56

my-slides

Host my slides: devops, kubernetes, life, etc
2
star
57

cleanup_old_files

Clean old files in an organized way
Python
2
star
58

terraform_jenkins_digitalocean

Define Jenkins job to create and provision digitalocean VMs by terraform
Shell
2
star
59

python-aws-cli-wrapper

โ˜๏ธ Wrapper layer of AWS CLI in Python
Python
2
star
60

cheatsheet-living-in-ca

๐Ÿ‘ช CheatSheet for living in Canifornia
2
star
61

quiz.dennyzhang.com

๐Ÿ“– Examine skills in a hard way
Shell
1
star
62

dennyzhang.github.io

dummy website
1
star
63

check_logfiles

nagios plugin to check log files
Perl
1
star
64

book-reading-cloud

๐Ÿ“– My book reading to be a good cloud engineer/architect
1
star
65

couchbase-cli-tool

Couchbase CLI Tools
Python
1
star
66

node_status_in_json

Query node status and return a structured json
Python
1
star
67

challenges-fluent-bit

Deep dive into fluent-bit
1
star
68

today-learning

Personal memo for #today-learnings in our DevOps slack group
1
star