logo
🚀 DevOps

Kubernetes

Kubernetes Cheat Sheet - 快速参考指南,收录常用语法、命令与实践。

📂 分类 · DevOps🧭 Markdown 速查🏷️ 2 个标签
#k8s#orchestration
向下滚动查看内容
返回全部 Cheat Sheets

Viewing and finding resources

Nodes
BASH
滚动查看更多
kubectl get no # Display all node information
kubectl get no -o wide # Show more information about all nodes
kubectl describe no # Display node details
kubectl get no -o yaml # Display node details in yaml format
kubectl get node --selector=[label_name] # Filter the node with the specified label
kubectl get nodes -o jsonpath='{.items[*].status.addresses[?(@.type="ExternalIP")].address}'
# Output the field information defined by the jsonpath expression
kubectl top node [node_name] # Display node (CPU/memory/storage) usage

Resource name: nodes, abbreviation: no

Pods
BASH
滚动查看更多
kubectl get po # Display all container group information
kubectl get po -o wide
kubectl describe po
kubectl get po --show-labels # View the labels of the container group
kubectl get po -l app=nginx
kubectl get po -o yaml
kubectl get pod [pod_name] -o yaml --export
kubectl get pod [pod_name] -o yaml --export > nameoffile.yaml
# Export container group information to yaml file in yaml format
kubectl get pods --field-selector status.phase=Running
# Use the field selector to filter out container group information

Resource name: pods, abbreviation: po

Namespaces
BASH
滚动查看更多
kubectl get ns
kubectl get ns -o yaml
kubectl describe ns

Resource name: namespaces, abbreviation: ns

Deployments
BASH
滚动查看更多
kubectl get deploy
kubectl describe deploy
kubectl get deploy -o wide
kubectl get deploy -o yaml

Resource name: deployments, abbreviation: deploy

Services
BASH
滚动查看更多
kubectl get svc
kubectl describe svc
kubectl get svc -o wide
kubectl get svc -o yaml
kubectl get svc --show-labels

Resource name: services, abbreviation: svc

Daemon Sets
BASH
滚动查看更多
kubectl get ds
kubectl describe ds --all-namespaces
kubectl describe ds [daemonset_name] -n [namespace_name]
kubectl get ds [ds_name] -n [ns_name] -o yaml

Resource name: daemonsets, abbreviation: ds

Events
BASH
滚动查看更多
kubectl get events
kubectl get events -n kube-system
kubectl get events -w

Resource name: events, abbreviation: ev

Logs
BASH
滚动查看更多
kubectl logs [pod_name]
kubectl logs --since=1h [pod_name]
kubectl logs --tail=20 [pod_name]
kubectl logs -f -c [container_name] [pod_name]
kubectl logs [pod_name] > pod.log
Service Accounts
BASH
滚动查看更多
kubectl get sa
kubectl get sa -o yaml
kubectl get serviceaccounts default -o yaml >./sa.yaml
kubectl replace serviceaccount default -f ./sa.yaml

Resource name: serviceaccounts, abbreviation: ev

Replica Sets
BASH
滚动查看更多
kubectl get rs
kubectl describe rs
kubectl get rs -o wide
kubectl get rs -o yaml

Resource name: replicasets, abbreviation: rs

Roles
BASH
滚动查看更多
kubectl get roles --all-namespaces
kubectl get roles --all-namespaces -o yaml
Secrets
BASH
滚动查看更多
kubectl get secrets
kubectl get secrets --all-namespaces
kubectl get secrets -o yaml
Config maps

Resource name: configmaps, abbreviation: cm

BASH
滚动查看更多
kubectl get cm
kubectl get cm --all-namespaces
kubectl get cm --all-namespaces -o yaml
Ingresses

Resource name: ingresses, abbreviation: ing

BASH
滚动查看更多
kubectl get ing
kubectl get ing --all-namespaces
Persistent Volumes

Resource name: persistentvolumes, abbreviation: pv

BASH
滚动查看更多
kubectl get pv
kubectl describe pv
Persistent volume declaration

Resource name: persistentvolumeclaims, abbreviation: pvc

BASH
滚动查看更多
kubectl get pvc
kubectl describe pvc
storage class

Resource name: storageclasses, Abbreviation: sc

BASH
滚动查看更多
kubectl get sc
kubectl get sc -o yaml
Multiple resources
BASH
滚动查看更多
kubectl get svc, po
kubectl get deploy, no
kubectl get all
kubectl get all --all-namespaces

Updating resources

Taint
BASH
滚动查看更多
kubectl taint [node_name] [taint_name]
Label
BASH
滚动查看更多
kubectl label [node_name] disktype=ssd
kubectl label [pod_name] env=prod
Maintain/Schedulable
BASH
滚动查看更多
kubectl cordon [node_name] # node maintenance
kubectl uncordon [node_name] # node is schedulable
clear
BASH
滚动查看更多
kubectl drain [node_name] # empty the node
Node/Pod
BASH
滚动查看更多
kubectl delete node [node_name]
kubectl delete pod [pod_name]
kubectl edit node [node_name]
kubectl edit pod [pod_name]
Stateless/Namespaced
BASH
滚动查看更多
kubectl edit deploy [deploy_name]
kubectl delete deploy [deploy_name]
kubectl expose deploy [deploy_name] --port=80 --type=NodePort
kubectl scale deploy [deploy_name] --replicas=5
kubectl delete ns
kubectl edit ns [ns_name]
Service
BASH
滚动查看更多
kubectl edit svc [svc_name]
kubectl delete svc [svc_name]
Daemon set
BASH
滚动查看更多
kubectl edit ds [ds_name] -n kube-system
kubectl delete ds [ds_name]
Service account
BASH
滚动查看更多
kubectl edit sa [sa_name]
kubectl delete sa [sa_name]
Notes
BASH
滚动查看更多
kubectl annotate po [pod_name] [annotation]
kubectl annotateno [node_name]

Create resources

Create pod
BASH
滚动查看更多
kubectl create -f [name_of_file]
kubectl apply -f [name_of_file]
kubectl run [pod_name] --image=nginx --restart=Never
kubectl run [pod_name] --generator=run-pod/v1 --image=nginx
kubectl run [pod_name] --image=nginx --restart=Never
Create Service
BASH
滚动查看更多
kubectl create svc nodeport [svc_name] --tcp=8080:80
Create a stateless application
BASH
滚动查看更多
kubectl create -f [name_of_file]
kubectl apply -f [name_of_file]
kubectl create deploy [deploy_name] --image=nginx
interaction
BASH
滚动查看更多
kubectl run [pod_name] --image=busybox --rm -it --restart=Never --sh
Output YAML
BASH
滚动查看更多
kubectl create deploy [deploy_name] --image=nginx --dry-run -o yaml > deploy.yaml
kubectl get po [pod_name] -o yaml --export > pod.yaml
Help
BASH
滚动查看更多
kubectl -h
kubectl create -h
kubectl run -h
kubectl explain deploy.spec

Miscellaneous

APIs
BASH
滚动查看更多
kubectl get --raw /apis/metrics.k8s.io/
Information
BASH
滚动查看更多
kubectl config
kubectl cluster-info
kubectl get componentstatus

Also See

相关 Cheat Sheets

1v1免费职业咨询
logo

Follow Us

linkedinfacebooktwitterinstagramweiboyoutubebilibilitiktokxigua

We Accept

/image/layout/pay-paypal.png/image/layout/pay-visa.png/image/layout/pay-master-card.png/image/layout/pay-airwallex.png/image/layout/pay-alipay.png

地址

Level 10b, 144 Edward Street, Brisbane CBD(Headquarter)
Level 2, 171 La Trobe St, Melbourne VIC 3000
四川省成都市武侯区桂溪街道天府大道中段500号D5东方希望天祥广场B座45A13号
Business Hub, 155 Waymouth St, Adelaide SA 5000

Disclaimer

footer-disclaimerfooter-disclaimer

JR Academy acknowledges Traditional Owners of Country throughout Australia and recognises the continuing connection to lands, waters and communities. We pay our respect to Aboriginal and Torres Strait Islander cultures; and to Elders past and present. Aboriginal and Torres Strait Islander peoples should be aware that this website may contain images or names of people who have since passed away.

匠人学院网站上的所有内容,包括课程材料、徽标和匠人学院网站上提供的信息,均受澳大利亚政府知识产权法的保护。严禁未经授权使用、销售、分发、复制或修改。违规行为可能会导致法律诉讼。通过访问我们的网站,您同意尊重我们的知识产权。 JR Academy Pty Ltd 保留所有权利,包括专利、商标和版权。任何侵权行为都将受到法律追究。查看用户协议

© 2017-2025 JR Academy Pty Ltd. All rights reserved.

ABN 26621887572