├── CONTRIBUTING.md ├── COPYRIGHT.md ├── README.md └── assets └── logo.png /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to our cheatsheet 2 | 3 | Our Commitment to Open Source can be found here 4 | 5 | 1. [Fork](https://help.github.com/articles/fork-a-repo/) this repository to your own GitHub account and then [clone](https://help.github.com/articles/cloning-a-repository/) it to your local device. 6 | 2. Create a new branch `git checkout -b MY_BRANCH_NAME` 7 | 3. Update new cheatsheet to your branch with [GPG sign](https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/managing-commit-signature-verification) 8 | 4. Pull request from your branch into this repository `master` branch 9 | 5. Waiting for reviewing from owners 10 | 6. Accept to pull request / Reject with comment to adjust your pull request 11 | -------------------------------------------------------------------------------- /COPYRIGHT.md: -------------------------------------------------------------------------------- 1 | # Copyright 2 | 3 | Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # KubeOps Kubernetes CheatSheet 2 | 3 | 4 | 5 | This is Kubernetes Cheatsheet based on Kubernetes API 1.19 version. 6 | 7 | **Facebook:** [Link](https://facebook.com/kubeopsskills) 8 | 9 | **Youtube:** [Link](https://www.youtube.com/c/kubeopsskills) 10 | 11 | # Copyright 12 | 13 | Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. 14 | 15 | ## Creating Objects 16 | 17 | | Name | Command | 18 | | ------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- | 19 | | Create resource | kubectl apply -f ./``.yaml | 20 | | Create from multiple files | kubectl apply -f ./``.yaml -f ./``.yaml | 21 | | Create all files in directory | kubectl apply -f ./`` | 22 | | Create from url | kubectl apply -f `https://` | 23 | | Create pod | kubectl run `` --image `` | 24 | | Create pod, then expose it as service | kubectl run `` --image `` --port `` --expose | 25 | | Create pod yaml file | kubectl run `` --image `image_name` --dry-run=client -o yaml > ``.yaml | 26 | | Create deployment | kubectl create deployment `` --image `` | 27 | | Create deployment yaml file | kubectl create deployment `` --image `` --dry-run=client -o yaml > ``.yaml | 28 | | Create service | kubectl create service `` `` --tcp=`` | 29 | | Create service yaml file | kubectl create service `` `` --tcp=`` --dry-run=client -o yaml > ``.yaml | 30 | | Expose service from pod/deployment | kubectl expose deployment `` --type=`` --port `` --target-port `` | 31 | | Create config map from key-value | kubectl create configmap `` --from-literal=`:` --from-literal=`:` | 32 | | Create config map from file | kubectl create configmap `` --from-file=`` | 33 | | Create config map from env file | kubectl create configmap `` --from-env-file=`` | 34 | | Create secret from key-value | kubectl create secret generic `` --from-literal=`:` --from-literal=`:` | 35 | | Create secret from file | kubectl create secret generic `` --from-file=`` | 36 | | Create job | kubectl create job `` --image=`` | 37 | | Create job from cronjob | kubectl create job `` --from=`cronjob/` | 38 | | Create cronjob | kubectl create cronjob --image=`` --schedule='``' -- `` `` | 39 | | Create inline yaml | cat <`
YAML CONTENT ``
EOF `` | 40 | 41 | ## Monitoring Usage Commands 42 | 43 | | Name | Command | 44 | | ----------------------------------- | ------------------------------ | 45 | | Get node cpu and memory utilization | kubectl top node `` | 46 | | Get pod cpu and memory utilization | kubectl top pods `` | 47 | 48 | ## Namespace Usage Commands 49 | 50 | | Name | Command | 51 | | ----------------------------------- | ------------------------------ | 52 | | Get all namespaces | kubectl get namespaces | 53 | | Get namespace | kubectl get namespaces `` | 54 | | Get namespace in yaml | kubectl get namespaces `` -o yaml | 55 | | Describe namespace | kubectl describe namespaces `` | 56 | | Execute command with specific namespace (Example) | kubectl get pods --namespace=`` | 57 | | Set default namespace for 'kubectl' | kubectl config set-context --current --namespace="``" | 58 | | Check current namespace | kubectl config view --minify \| grep namespace: | 59 | | Cleanup namespace with specific namespace| kubectl delete all --all --namespace="``"| 60 | | Cleanup namespace (Be careful, make sure you're right namespace) | kubectl delete all --all | 61 | 62 | ## Node Commands 63 | 64 | | Name | Command | 65 | | ---------------- | -------------------------------------- | 66 | | Describe node | kubectl describe node `` | 67 | | Get node in yaml | kubectl get node `` -o yaml | 68 | | Get node | kubectl get node `` | 69 | | Drain node | kubectl drain node `` | 70 | | Cordon node | kubectl cordon node `` | 71 | | Uncordon node | kubectl uncordon node `` | 72 | 73 | ## Pod Commands 74 | 75 | | Name | Command | 76 | | ------------------------ | ------------------------------------------------------------------------------------------------- | 77 | | Get pod | kubectl get pod `` | 78 | | Get pod in yaml | kubectl get pod `` -o yaml | 79 | | Get pod wide information | kubectl get pod `` -o wide | 80 | | Get pod with watch | kubectl get pod `` -w | 81 | | Edit pod | kubectl edit pod `` | 82 | | Describe pod | kubectl describe pod `` | 83 | | Delete pod | kubectl delete pod `` | 84 | | Log pod | kubectl logs pod `` | 85 | | Tail -f pod | kubectl logs pod -f `` | 86 | | Execute into pod | kubectl exec -it pod `` -- /bin/bash | 87 | | Running Temporary Image | kubectl run `` --image=curlimages/curl --rm -it --restart=Never -- curl `` | 88 | 89 | ## Deployment Commands 90 | 91 | | Name | Command | 92 | | ------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | 93 | | Get deployment | kubectl get deployment `` | 94 | | Get deployment in yaml | kubectl get deployment `` -o yaml | 95 | | Get deployment wide information | kubectl get deployment `` -o wide | 96 | | Edit deployment | kubectl edit deployment `` | 97 | | Describe deployment | kubectl describe deployment `` | 98 | | Delete deployment | kubectl delete deployment `` | 99 | | Log deployment | kubectl logs deployment/`deployment_name` -f | 100 | | Update image | kubectl set image deployment `` ``=`` | 101 | | Scale deployment with replicas | kubectl scale deployment `` --replicas `` | 102 | | Autoscaling deployment | kubectl autoscale deployment `` --min=`` --max=`` --cpu-percent=`` | 103 | 104 | ## Service Commands 105 | 106 | | Name | Command | 107 | | ---------------------------- | --------------------------------------- | 108 | | Get service | kubectl get service `` | 109 | | Get service in yaml | kubectl get service `` -o yaml | 110 | | Get service wide information | kubectl get service `` -o wide | 111 | | Edit service | kubectl edit service `` | 112 | | Describe service | kubectl describe service `` | 113 | | Delete service | kubectl delete service `` | 114 | 115 | ## Endpoints Commands 116 | 117 | | Name | Command | 118 | | ------------- | ---------------------------------------- | 119 | | Get endpoints | kubectl get endpoints `` | 120 | 121 | ## Ingress Commands 122 | 123 | | Name | Command | 124 | | ---------------------------- | ----------------------------------------- | 125 | | Get ingress | kubectl get ingress | 126 | | Get ingress in yaml | kubectl get ingress -o yaml | 127 | | Get ingress wide information | kubectl get ingress -o wide | 128 | | Edit ingress | kubectl edit ingress `` | 129 | | Describe ingress | kubectl describe ingress `` | 130 | | Delete ingress | kubectl delete ingress `` | 131 | 132 | ## DaemonSet Commands 133 | 134 | | Name | Command | 135 | | --------------------- | ------------------------------------------------ | 136 | | Get daemonset | kubectl get daemonset `` | 137 | | Get daemonset in yaml | kubectl get daemonset `` -o yaml | 138 | | Edit daemonset | kubectl edit daemonset `` | 139 | | Describe daemonset | kubectl describe daemonset `` | 140 | | Delete daemonset | kubectl delete deployment `` | 141 | 142 | ## StatefulSet Commands 143 | 144 | | Name | Command | 145 | | ----------------------- | ---------------------------------------------------- | 146 | | Get statefulset | kubectl get statefulset `` | 147 | | Get statefulset in yaml | kubectl get statefulset `` -o yaml | 148 | | Edit statefulset | kubectl edit statefulset `` | 149 | | Describe statefulset | kubectl describe statefulset `` | 150 | | Delete statefuleset | kubectl delete statefulset `` | 151 | 152 | ## ConfigMaps Commands 153 | 154 | | Name | Command | 155 | | --------------------- | ------------------------------------------------ | 156 | | Get configmap | kubectl get configmap `` | 157 | | Get configmap in yaml | kubectl get configmap `` -o yaml | 158 | | Edit configmap | kubectl edit configmap `` | 159 | | Describe configmap | kubectl describe configmap `` | 160 | | Delete configmap | kubectl delete configmap `` | 161 | 162 | ## Secret Commands 163 | 164 | | Name | Command | 165 | | ------------------ | ------------------------------------------ | 166 | | Get secret | kubectl get secret `` | 167 | | Get secret in yaml | kubectl get secret `` -o yaml | 168 | | Edit secret | kubectl edit secret `` | 169 | | Describe secret | kubectl describe secret `` | 170 | | Delete secret | kubectl delete secret `` | 171 | 172 | ## Rollout Commands 173 | 174 | | Name | Command | 175 | | ---------------------------------------- | ------------------------------------------------------------------------------------- | 176 | | Restart deployment | kubectl rollout restart deployment `` | 177 | | Undo deployment with the latest revision | kubectl rollout undo deployment `` | 178 | | Undo deployment with specified revision | kubectl rollout undo deployment `` --to-revision `` | 179 | | Get all revisions of deployment | kubectl rollout history deployment `` | 180 | | Get specified revision of deployment | kubectl rollout history deployment `` --revision=`` | 181 | 182 | ## Job Commands 183 | 184 | | Name | Command | 185 | | ---------------- | ------------------------------------ | 186 | | Get job | kubectl get job `` | 187 | | Get job in yaml | kubectl get job `` -o yaml | 188 | | Edit job in yaml | kubectl edit job `` | 189 | | Describe job | kubectl describe job `` | 190 | | Delete job | kubectl delete job `` | 191 | 192 | ## Cronjob Commands 193 | 194 | | Name | Command | 195 | | ------------------- | -------------------------------------------- | 196 | | Get cronjob | kubectl get cronjob `cronjob_name` | 197 | | Get cronjob in yaml | kubectl get cronjob `` -o yaml | 198 | | Edit cronjob | kubectl edit cronjob `` | 199 | | Describe cronjob | kubectl describe cronjob `` | 200 | | Delete cronjob | kubectl delete cronjob `` | 201 | 202 | ## Network Policy Commands 203 | 204 | | Name | Command | 205 | | ---------------------------------- | -------------------------------------------------------- | 206 | | Get networkpolicy | kubectl get networkpolicy `` | 207 | | Get networkpolicy in yaml | kubectl get networkpolicy `` -o yaml | 208 | | Get networkpolicy wide information | kubectl get networkpolicy `` -o wide | 209 | | Edit networkpolicy | kubectl edit networkpolicy `` | 210 | | Describe networkpolicy | kubectl describe networkpolicy `` | 211 | | Delete networkpolicy | kubectl delete networkpolicy `` | 212 | 213 | ## Persistence Volume Commands 214 | 215 | | Name | Command | 216 | | ------------------------------ | ------------------------------------------------- | 217 | | Get persistence volume | kubectl get pv `` | 218 | | Get persistence volume in yaml | kubectl get pv `` -o yaml | 219 | | Edit persistence volume | kubectl edit pv `` | 220 | | Describe persistence volume | kubectl describe pv `` | 221 | | Delete persistence volume | kubectl delete pv `` | 222 | 223 | ## Persistence Volume Claim Commands 224 | 225 | | Name | Command | 226 | | ------------------------------------ | -------------------------------------------------------- | 227 | | Get persistence volume claim | kubectl get pvc `` | 228 | | Get persistence volume claim in yaml | kubectl get pvc `` -o yaml | 229 | | Edit persistence volume claim | kubectl edit pvc `` | 230 | | Describe persistence volume claim | kubectl describe pvc `` | 231 | | Delete persistence volume claim | kubectl delete pvc `` | 232 | 233 | ## Labels and Selectors Commands 234 | 235 | | Name | Command | 236 | | ---------------------------------------------- | ------------------------------------------------------------------ | 237 | | Show labels of node,pod and deployment | kubectl get `` --show-labels | 238 | | Attach labels to `` | kubectl label `` `` `=` | 239 | | Remove labels from `` | kubectl label `` `` ``- | 240 | | Select node,pod and deployment by using labels | kubectl get `` -l `=` | 241 | | Delete all resources by using labels | kubectl delete all -l `=` | 242 | 243 | ## Role-Based Access Control (RBAC) Commands 244 | 245 | | Name | Command | 246 | | -------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- | 247 | | List current user privilleges with default namespace | kubectl auth can-i --list | 248 | | List specified user privilleges with default namespace | kubectl auth can-i --list --as `` | 249 | | List current user privilleges with specified namespace | kubectl auth can-i --list -n `` | 250 | | List specified user privilleges with specified namespace | kubectl auth can-i --list --as `` -n `` | 251 | | Verify if current user is able to do something with resource | kubectl auth can-i `` `` | 252 | | Verify if specified user is able to do something with resource | kubectl auth can-i `` `` --as `` | 253 | | Create service account | kubectl create serviceaccount `` | 254 | | Create role and define resource privilleges | kubectl create role `` --resource=`` --verb=`` | 255 | | Create cluster role and define cluster resource privilleges | kubectl create clusterrole `` --resource=`` --verb=`` | 256 | | Create role binding with service account | kubectl create rolebinding `` --role `` --serviceaccount `` | 257 | | Create cluster role binding with service account | kubectl create clusterrolebinding `` --clusterrole `` --serviceaccount `` | 258 | | Create role binding with user | kubectl create rolebinding `` --role `` --user `` | 259 | | Create cluster role binding with user | kubectl create clusterrolebinding `` --clusterrole `` --user `` | 260 | 261 | ## API Resource 262 | 263 | | Name | Command | 264 | | -------------------------------------------------------------- | --------------------- | 265 | | Print the supported API resources on the Kubernetes API server | kubectl api-resources | 266 | 267 | ## References 268 | 269 | **Kubernetes Document:** [Link](https://kubernetes.io/docs/home/) 270 | 271 | **Kubernetes Command:** [Link](https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands) 272 | 273 | **Kubernetes API Reference:** [Link](https://kubernetes.cn/docs/reference/generated/kubernetes-api/v1.19/) 274 | 275 | **Kubernetes CheatSheet** [Link](https://kubernetes.io/docs/reference/kubectl/cheatsheet/) 276 | -------------------------------------------------------------------------------- /assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kubeopsskills/kubernetes-cheatsheet/323e469440c59672446003d33033d4e77bf056e2/assets/logo.png --------------------------------------------------------------------------------