kubectl命令管理

kubectl命令管理

查看更多帮助命令

[root@k8s-master ~]# kubectl --help

创建一个命名空间

[root@k8s-master ~]# kubectl create namespace yunjisuan

namespace "yunjisuan" created

[root@k8s-master ~]# kubectl get namespace /ns 都可以

查看信息所有

[root@k8s-master ~]# kubectl get all

NAME                        READY     STATUS    RESTARTS   AGE

po/nginx-5fc8fd597f-4q22p   1/1       Running   0          9m

po/nginx-5fc8fd597f-8h94r   1/1       Running   0          11m

po/nginx-5fc8fd597f-ppfhf   1/1       Running   0          11m

查看资源的yaml文件信息,并可以修改

我直接修改nginx的版本号为1.12

[root@k8s-master ~]# kubectl edit deploy/nginx

 template:

    metadata:

      creationTimestamp: null

      labels:

        run: nginx

    spec:

      containers:

      - image: nginx:1.12

        imagePullPolicy: Always

查看yaml文件资源已经修改成功

[root@k8s-master ~]# kubectl describe po/nginx-5fc8fd597f-4q22p

 nginx:

    Container ID:   docker://706661f913c042c2aa2edfd2d649eccade76b9bad71e53052f69588749580f4e

    Image:          nginx:1.12

查看进群信息

[root@k8s-master ~]# kubectl cluster-info

Kubernetes master is running at http://localhost:8080

kubernetes-dashboard is running at http://localhost:8080/api/v1/namespaces/kube-system/services/kubernetes-dashboard/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

查看pod日志

[root@k8s-master ~]# kubectl logs nginx-5fc8fd597f-4q22p

进入pod

[root@k8s-master ~]# kubectl exec -it nginx-5fc8fd597f-4q22p bash

root@nginx-5fc8fd597f-4q22p:/#

查看pod目录文件

[root@k8s-master ~]# kubectl exec -it nginx-5fc8fd597f-4q22p -- ls

bin   dev  home  lib64 mnt  proc  run  srv  tmp  var

boot  etc  lib  media opt  root  sbin  sys  usr

查看版本

[root@k8s-master ~]# kubectl version

删除资源

[root@k8s-master ~]# kubectl delete deploy/nginx

[root@k8s-master ~]# kubectl delete svc/nginx

查看资源

[root@k8s-master ~]# kubectl get all

原文地址:https://www.cnblogs.com/zc1741845455/p/11140004.html