您当前的位置: 首页 >  kubernetes

科技D人生

暂无认证

  • 0浏览

    0关注

    1550博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Kubernetes学习总结(14)—— Kubernetes 实用命令总结

科技D人生 发布时间:2021-12-22 11:02:14 ,浏览量:0

一、Pods 1、Get all pods in the current namespace
kubectl get pods
2、Get pods in all namespaces
kubectl get pods --all-namespaces
3、Get pods with more details
kubectl get pods -o wide
4、Get the yaml for a pod
kubectl get pod  -o yaml
5、Inspect a pod
kubectl describe pods 
6、Get pods sorted by a metric
kubectl get pods --sort-by='.status.containerStatuses[0].restartCount'
7、Get pods with their labels
kubectl get pods --show-labels
8、Get pods that match a label
kubectl get pods -l =
9、Forward traffic from a localhost port to a pod port
kubectl port-forward  :
10、Run a command on a pod
kubectl exec  -- 
11、Run a command on a container in a pod
kubectl exec  -c  -- 
二、Secrets 1、Get all secrets in the current namespace
kubectl get secrets
2、Get secrets in all namespaces
kubectl get secrets --all-namespaces
3、Get secrets with more details
kubectl get secrets -o wide
4、Get the contents of a secret
kubectl get secrets  -o yaml 
三、Services 1、Get all services in the current namespace
kubectl get services
2、Get services in all namespaces
kubectl get service --all-namespaces
3、Get services with more details
kubectl get service -o wide
4、Get the yaml for a services
kubectl get service  -o yaml
5、Inspect a service
kubectl describe service 
6、Get service's labels
kubectl get service --show-labels
7、Get services that match a label
kubectl get service -l =
四、Updating Resources 1、Roll a new version of a deployment
kubectl set image deployment/ =image:
2、Check the deployment history
kubectl rollout history deployment/
3、Rollback a deployment
kubectl rollout undo deployment/
4、Rollback to a specific version
kubectl rollout undo deployment/ --to-revision=2
5、Watch a rolling update
kubectl rollout status -w deployment/
6、Restart the rolling deploy
kubectl rollout restart deployment/
7、Edit a resource’s yaml
kubectl edit deployment/
8、Scale a deployment to 3 pods
kubectl scale --replicas=3 deployment/
9、Delete a pod
kubectl delete pod 
五、Context 1、Show contexts
kubectl config get-contexts
2、Show current context
kubectl config current-context
3、Switch context to another cluster
kubectl config use-context 
4、Change Namespace
kubectl config set-context --current --namespace=
六、Logs 1、Show logs (stdout) of a pod
kubectl logs 
2、Show logs (stdout) of pods that match a label
kubectl logs -l =
3、Show logs of a previous instantiation of a container
kubectl logs  --previous
4、Show logs for a specific container in a pod (i.e. init container)
kubectl logs  -c 
5、Following logs from a pod
kubectl logs -f 
6、Follow all logs from a pod that match a label
kubectl logs -f -l = --all-containers
7、Show logs with verbosity level of logs from 0 - 9
kubectl logs  --v=
七、Deployments 1、Get all deployments in the current namespace
kubectl get deployment
2、Get deployments in all namespaces
kubectl get deployment --all-namespaces
3、Get deployments with more details
kubectl get deployment -o wide
4、Get the yaml for a deployment
kubectl get deployment  -o yaml
5、Inspect a deployment
kubectl describe deployment 
6、Get deployment's labels
kubectl get deployment --show-labels
7、Get deployments that match a label
kubectl get deployment -l =
八、Ingress 1、Get all ingress in the current namespace
kubectl get ingress
2、Get ingress in all namespaces
kubectl get ingress --all-namespaces
3、Get ingress with more details
kubectl get ingress -o wide
4、Get the yaml for a ingress
kubectl get ingress  -o yaml
5、Inspect a ingress
kubectl describe ingress 
6、Get ingress labels
kubectl get ingress --show-labels
7、Get ingress that match a label
kubectl get ingress -l =
九、Creating Resources 1、Create a kubernetes resource from a file
kubectl apply -f ./.yaml
2、Create kubernetes resources from multiple files
kubectl apply -f ./.yaml -f ./.yaml
3、Create resources from all manifest files in a directory
kubectl apply -f ./
4、Create resource from a url
kubectl apply -f 
5、Start a single instance of an image
kubectl create deployment  --image=
十、Nodes 1、Mark node as unschedulable
kubectl cordon 
2、Drain a node for maintenance
kubectl drain 
3、Mark node as schedulable
kubectl uncordon 
4、Show ‘top’ metrics for a node
kubectl top node 
5、Display addresses of the master and services
kubectl cluster-info
6、ump current cluster state to stdout
kubectl cluster-info dump
7、Show a list of eligible kube resource (i.e. pods, service, pv, etc)
kubectl api-resources
8、Show a list of eligible kube resources in your namespace
kubectl api-resources --namespaced=true

关注
打赏
1662604032
查看更多评论
立即登录/注册

微信扫码登录

0.0426s