zoukankan      html  css  js  c++  java
  • Kubernetes(四):常用操作

     1. 查看集群版本

    [root@k8s-m1 ~]# kubectl version --short=true
    Client Version: v1.15.2
    Server Version: v1.15.2
    

     2.查看集群信息

    [root@k8s-m1 ~]# kubectl cluster-info
    Kubernetes master is running at https://192.168.2.124:6443
    KubeDNS is running at https://192.168.2.124:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
    

     3. 查看所有node节点

    [root@k8s-m1 ~]# kubectl get nodes
    NAME     STATUS   ROLES    AGE   VERSION
    k8s-m1   Ready    master   27h   v1.15.2
    k8s-n1   Ready    <none>   27h   v1.15.2
    k8s-n2   Ready    <none>   27h   v1.15.2
    

     4. 查看所有资源类型

    # 第二列是缩写,一样可以被引用
    [root@k8s-m1 ~]# kubectl api-resources
    NAME                              SHORTNAMES   APIGROUP                       NAMESPACED   KIND
    bindings                                                                      true         Binding
    componentstatuses                 cs                                          false        ComponentStatus
    configmaps                        cm                                          true         ConfigMap
    endpoints                         ep                                          true         Endpoints
    events                            ev                                          true         Event
    limitranges                       limits                                      true         LimitRange
    namespaces                        ns                                          false        Namespace
    nodes                             no                                          false        Node
    persistentvolumeclaims            pvc                                         true         PersistentVolumeClaim
    persistentvolumes                 pv                                          false        PersistentVolume
    pods                              po                                          true         Pod
    

     5. 查看所有名称空间资源

    [root@k8s-m1 ~]# kubectl get ns
    NAME              STATUS   AGE
    default           Active   28h
    kube-node-lease   Active   28h
    kube-public       Active   28h
    kube-system       Active   28h
    

     6. 查看pod资源

    # 默认查看的是default名称空间下的pod,如果查看其它名称空间需要用-n指定
    [root@k8s-m1 ~]# kubectl get pods
    [root@k8s-m1 ~]# kubectl get pods -n kube-system
    NAME                             READY   STATUS    RESTARTS   AGE
    coredns-5c98db65d4-mzw28         1/1     Running   0          28h
    coredns-5c98db65d4-zl5cs         1/1     Running   0          28h
    etcd-k8s-m1                      1/1     Running   0          28h
    kube-apiserver-k8s-m1            1/1     Running   0          28h
    kube-controller-manager-k8s-m1   1/1     Running   0          28h
    kube-flannel-ds-amd64-qd5js      1/1     Running   0          28h
    kube-flannel-ds-amd64-qq9td      1/1     Running   0          28h
    kube-flannel-ds-amd64-xtpcg      1/1     Running   0          28h
    kube-proxy-6q5dj                 1/1     Running   0          28h
    kube-proxy-9p5qd                 1/1     Running   0          28h
    kube-proxy-s97s9                 1/1     Running   0          28h
    kube-scheduler-k8s-m1            1/1     Running   0          28h
    

     7. 创建一个名为nginx-deploy的deployment对象

    [root@k8s-m1 ~]# kubectl run nginx-deploy --image=nginx:1.14 --replicas=2
    # --image:指定镜像名字
    # --replicas:为容器创建多少副本
    [root@k8s-m1 ~]# kubectl get deploy -o wide
    NAME           READY   UP-TO-DATE   AVAILABLE   AGE     CONTAINERS     IMAGES       SELECTOR
    nginx-deploy   2/2     2            2           3d14h   nginx-deploy   nginx:1.14   run=nginx-deploy
    # 可以看到自动分配到两个Node节点上
    [root@k8s-m1 ~]# kubectl get pod -o wide
    NAME                           READY   STATUS    RESTARTS   AGE     IP           NODE     NOMINATED NODE   READINESS GATES
    nginx-deploy-cdb7cc65c-949kr   1/1     Running   0          3d14h   10.244.1.3   k8s-n1   <none>           <none>
    nginx-deploy-cdb7cc65c-hm6lh   1/1     Running   2          3d14h   10.244.2.4   k8s-n2   <none>           <none>
    

     8. 查看某名称空间中标签是k8s-app的pod

    [root@k8s-m1 ~]# kubectl get pod -l k8s-app -n kube-system
    NAME                       READY   STATUS    RESTARTS   AGE
    coredns-5c98db65d4-mzw28   1/1     Running   0          4d
    coredns-5c98db65d4-zl5cs   1/1     Running   0          4d
    kube-proxy-6q5dj           1/1     Running   0          3d23h
    kube-proxy-9p5qd           1/1     Running   0          4d
    kube-proxy-s97s9           1/1     Running   0          3d23h
    

     9. 查看pod对象的日志

    [root@k8s-m1 ~]# curl 10.244.2.4
    [root@k8s-m1 ~]# kubectl logs -f nginx-deploy-cdb7cc65c-hm6lh
    10.244.0.0 - - [18/Oct/2019:07:32:13 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.29.0" "-"
    # -f:相当于tail的-f参数
    

     10. 在容器中执行命令

    [root@k8s-m1 ~]# kubectl exec nginx-deploy-cdb7cc65c-hm6lh -- ls -l /home
    total 0
    

      
      

    写作不易,转载请注明出处,谢谢~~

  • 相关阅读:
    trailRenderer
    通过sysobjects快速查找SQLServer中是否有某个表、视图、存储过程等对象实操
    浅谈信息系统(IT)项目管理-序幕
    使用open xml 判断sharepoint文档是否损坏
    Sharepoint the file is locked for use domainuser edit.文件被锁定,解锁方式
    sharepoint 列表库指定序号规则
    Biztalk 宏
    Biztalk 在流程中定义将消息保存为文件的文件名
    Biztalk 2013 新特性简介(英)
    devexpress gridview,selectedrowchanged
  • 原文地址:https://www.cnblogs.com/ccbloom/p/11697163.html
Copyright © 2011-2022 走看看