当前位置:网站首页>The most complete kubernetes core command of the latest version so far

The most complete kubernetes core command of the latest version so far

2022-06-26 11:29:00 BOGO

Put your years of k8s The operation command is contributed by taking notes , I hope I can help you !

# View all namespace Of pods Operation of the 
kubectl get pods --all-namespaces
# Check the details pods, Remember to follow namespace Name 
kubectl get pods  kubernetes-dashboard-76479d66bb-nj8wr --namespace=kube-system
#  see pods Specific information 
kubectl get pods -o wide kubernetes-dashboard-76479d66bb-nj8wr --namespace=kube-system
#  View cluster health status 
kubectl get cs
#  Get all deployment
kubectl get deployment --all-namespaces
#  List the  namespace  All in  pod  Include uninitialized 
kubectl get pods --include-uninitialized
#  see deployment()
kubectl get deployment nginx-app
#  see rc and servers
kubectl get rc,services
#  see pods structural information ( a key , Through this to see the log analysis error )
#  For controllers and services ,node Equally effective 
kubectl describe pods xxxxpodsname --namespace=xxxnamespace
#  Other controllers are similar , Namely kubectl get  controller   The specific name of the controller 
#  see pod journal 
kubectl logs $POD_NAME
#  see pod Variable 
kubectl exec my-nginx-5j8ok -- printenv | grep SERVICE
#  colony 
kubectl get cs           #  Cluster health 
kubectl cluster-info     #  The operation of cluster core components 
kubectl get namespaces    #  Table space name 
kubectl version           #  edition 
kubectl api-versions      # API
kubectl get events       #  Check out the events 
kubectl get nodes      // Get all nodes 
kubectl delete node k8s2  // Delete node 
kubectl rollout status deploy nginx-test
#  establish 
kubectl create -f ./nginx.yaml           #  Create resources 
kubectl create -f .                            #  Create all... In the current directory yaml resources 
kubectl create -f ./nginx1.yaml -f ./mysql2.yaml     #  Create resources with multiple files 
kubectl create -f ./dir                        #  Use all the manifest files in the directory to create resources 
kubectl create -f https://git.io/vPieo         #  Use  url  To create resources 
kubectl run -i --tty busybox --image=busybox    ---- Create... With a terminal pod
kubectl run nginx --image=nginx                #  Start a  nginx  example 
kubectl run mybusybox --image=busybox --replicas=5    ---- Start multiple pod
kubectl explain pods,svc                       #  obtain  pod  and  svc  Documents 
#  to update 
kubectl rolling-update python-v1 -f python-v2.json           #  Scroll to update  pod frontend-v1
kubectl rolling-update python-v1 python-v2 --image=image:v2  #  Update resource name and update image 
kubectl rolling-update python --image=image:v2                 #  to update  frontend pod  In the mirror 
kubectl rolling-update python-v1 python-v2 --rollback        #  Exit the existing rolling update in progress 
cat pod.json | kubectl replace -f -                              #  be based on  stdin  Input  JSON  Replace  pod
 Forced replacement , Delete and recreate resources . Can cause service disruption .
kubectl replace --force -f ./pod.json
 by  nginx RC  Create services , Enable local  80  Port to the... On the container  8000  port 
kubectl expose rc nginx --port=80 --target-port=8000
 
 Update single container  pod  The mirror version of (tag) To  v4
kubectl get pod nginx-pod -o yaml | sed 's/\(image: myimage\):.*$/\1:v4/' | kubectl replace -f -
kubectl label pods nginx-pod new-label=awesome                      #  Add tags 
kubectl annotate pods nginx-pod icon-url=http://goo.gl/XXBTWq       #  adding annotations 
kubectl autoscale deployment foo --min=2 --max=10                #  Automatic extension  deployment “foo”
#  Edit resources 
kubectl edit svc/docker-registry                      #  The editor's name is  docker-registry  Of  service
KUBE_EDITOR="nano" kubectl edit svc/docker-registry   #  Use other editors 
#  Dynamic scaling pod
kubectl scale --replicas=3 rs/foo                                 #  take foo The replica set becomes 3 individual 
kubectl scale --replicas=3 -f foo.yaml                            #  The zoom “foo” The resource specified in .
kubectl scale --current-replicas=2 --replicas=3 deployment/mysql  #  take deployment/mysql from 2 A into 3 individual 
kubectl scale --replicas=5 rc/foo rc/bar rc/baz                   #  Change the number of multiple controllers 
kubectl rollout status deploy deployment/mysql                         #  Check the change progress 
#  Delete 
kubectl delete -f ./pod.json                                              #  Delete  pod.json  Of the type and name defined in the file  pod
kubectl delete pod,service baz foo                                        #  Delete the name “baz” Of  pod  And called “foo” Of  service
kubectl delete pods,services -l name=myLabel                              #  Delete has  name=myLabel  Labeled  pod  and  serivce
kubectl delete pods,services -l name=myLabel --include-uninitialized      #  Delete has  name=myLabel  Labeled  pod  and  service, Include uninitialized 
kubectl -n my-ns delete po,svc --all #  Delete  my-ns namespace All under  pod  and  serivce, Include uninitialized 
kubectl delete pods prometheus-7fcfcb9f89-qkkf7 --grace-period=0 --force  Mandatory deletion 

#  Interaction 
kubectl logs nginx-pod                                 # dump  Output  pod  Log (stdout)
kubectl logs nginx-pod -c my-container                 # dump  Output  pod  Log of the container in (stdout,pod  Use when there are multiple containers in )
kubectl logs -f nginx-pod                              #  Streaming output  pod  Log (stdout)
kubectl logs -f nginx-pod -c my-container              #  Streaming output  pod  Log of the container in (stdout,pod  Use when there are multiple containers in )
kubectl run -i --tty busybox --image=busybox -- sh  #  Interactive  shell  How to run  pod
kubectl attach nginx-pod -i                            #  Connect to a running container 
kubectl port-forward nginx-pod 5000:6000               #  forward  pod  Medium  6000  Port to local  5000  port 
kubectl exec nginx-pod -- ls /                         #  Execute the command in an existing container ( In the case of only one container )
kubectl exec nginx-pod -c my-container -- ls /         #  Execute the command in an existing container (pod  In the case of multiple containers )
kubectl top pod POD_NAME --containers               #  According to specified  pod And container metrics 
#  Scheduling configuration 
$ kubectl cordon k8s-node                                                #  Mark  my-node  Not schedulable 
$ kubectl drain k8s-node                                                 #  Empty  my-node  To be maintained 
$ kubectl uncordon k8s-node                                              #  Mark  my-node  Schedulable 
$ kubectl top node k8s-node                                              #  Show  my-node  A measure of 
$ kubectl cluster-info dump                                             #  Output the current cluster state to  stdout                                    
$ kubectl cluster-info dump --output-directory=/path/to/cluster-state   #  Output the current cluster state to  /path/to/cluster-state
# If the key and the effect of the stain (taint) Already exists , Replace... With the specified value 
$ kubectl taint nodes foo dedicated=special-user:NoSchedule
原网站

版权声明
本文为[BOGO]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/177/202206260950314859.html