Kubernetes Common Commands

Source: Internet
Author: User
Tags etcd

Kubectl Get

1. Query node, nodes or node or no

$ kubectl get noNAME      STATUS    ROLES     AGE       VERSIONmaster1   Ready       master     16h         v1.9.2master2   Ready       master     16h         v1.9.2master3   Ready       master     16h         v1.9.2

2. Querying component Status, Componentstatuses or CS

$ kubectl get csNAME                 STATUS    MESSAGE             ERRORscheduler            Healthy   ok                  controller-manager   Healthy   ok                  etcd-1               Healthy   {"health":"true"}   etcd-2               Healthy   {"health":"true"}   etcd-0               Healthy   {"health":"true"}

3. Querying the name space, namespaces or NS

$ kubectl get nsNAME          STATUS    AGEdefault       Active    16hkube-public   Active    16hkube-system   Active    16h

All of the following queries, the default Defalut name space,-n Specify the name of the namespace, specify all the name of the space--all-namespaces
4. Query pod,pods or pod or PO

$ kubectl get podNAME                              READY     STATUS    RESTARTS   AGEkube-apiserver-master1            1/1       Running   0          16hkube-apiserver-master2            1/1       Running   0          16hkube-apiserver-master3            1/1       Running   0          16h

Add parameter-o wide to display the running node

$ kubectl get pod -n kube-system -o wideNAME                              READY     STATUS    RESTARTS   AGE       IP              NODEkube-apiserver-master1            1/1       Running   0          16h       192.168.6.101   master1kube-apiserver-master2            1/1       Running   0          16h       192.168.6.102   master2kube-apiserver-master3            1/1       Running   0          16h       192.168.6.103   master3

5. Query service,services or service or Svc

$ kubectl  get service --all-namespacesNAMESPACE     NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)               AGEdefault             kubernetes   ClusterIP   10.96.0.1         <none>              443/TCP              16hkube-system   kube-dns      ClusterIP   10.96.0.10       <none>              53/UDP,53/TCP   16h

6.kind classification query, replicationcontrollers or RC, deployments or deploy, Daemonsets or DS

$ kubectl  get deployments --all-namespaces NAMESPACE     NAME       DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGEkube-system      kube-dns   1               1                  1                      1                    16h

7. Query All

$ kubectl  get all --all-namespaces
Kubectl Delete

1. Delete a node

$ kubectl delete node node1

2. Delete Pod

$ kubectl delete pod $(pod_name) -n $(namespace-name)

3. Delete Services

$ kubectl delete svc $(svc_name) -n $(namespace-name)
Update Maintenance

1. Manual dynamic extension Copy, scale

$ kubectl get Deployment -n test-appNAME          DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGEhello-world   3               3                  3                       3                   13h$ kubectl scale deployments hello-world --replicas=2 -n test-appdeployment "hello-world" scaled$ kubectl get Deployment -n test-app                            NAME          DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGEhello-world   2                2                  2                      2                   14h

2. According to the pod load automatic extension copy, Autoscale

$ kubectl autoscale deployments hello-world --min=2 --max=5 -n test-app

3. Update Rollback Pod,rolling-update
Rolling-update need to make sure the new version has different name,version and labels, otherwise it will error

$ kubectl rolling-update hello-world -f hello-world.yaml$ kubectl rolling-update hello-world --rollback
Problem Locator

1. Querying Object Details

$ kubectl describe pod kube-proxy-ftkx5 -n kube-system

2. Query log

$ kubectl logs -f  kube-proxy-ftkx5 -n kube-system

3. Enter container Run command, if Pod has more than one container, use-C to specify container

$ kubectl exec kube-dns-6f4fd4bdf-b7txf  -c dnsmasq hostname -n kube-systemkube-dns-6f4fd4bdf-b7txf

Kubernetes Common Commands

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.