• k8s 命令


    roles :      kubectl label nodes   node-hostname  node-role.kubernetes.io/master=                      减号就是删除roles,等号就是增加roles

    [root@k8s-master14 ~]# kubectl get node
    NAME           STATUS   ROLES    AGE     VERSION
    k8s-master12   Ready    master   4h15m   v1.15.1
    k8s-master13   Ready    <none>   13d     v1.15.1
    k8s-master14   Ready    master   6h17m   v1.15.1
    k8s-node01     Ready    <none>   13d     v1.15.1
    k8s-node02     Ready    <none>   13d     v1.15.1
    
    #减号就是删除roles,等号就是增加roles
    [root@k8s-master14 ~]# kubectl label nodes k8s-master13  node-role.kubernetes.io/master=
    node/k8s-master13 labeled
    
    [root@k8s-master14 ~]# kubectl get node
    NAME           STATUS   ROLES    AGE     VERSION
    k8s-master12   Ready    master   4h18m   v1.15.1
    k8s-master13   Ready    master   13d     v1.15.1
    k8s-master14   Ready    master   6h20m   v1.15.1
    k8s-node01     Ready    <none>   13d     v1.15.1
    k8s-node02     Ready    <none>   13d     v1.15.1
    

    lables  nodeSelector定向调度, 减号就是删除,kubectl label node <node-name> <label-key>-

    #添加lable
    [root@k8s-master13 ~]# kubectl label nodes k8s-node01 nodepool=pay
    node/k8s-node01 labeled
    
    [root@k8s-master13 ~]# kubectl get node --show-labels  
    NAME           STATUS     ROLES    AGE   VERSION   LABELS
    k8s-master12   NotReady   master   13d   v1.15.1   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-master12,kubernetes.io/os=linux,node-role.kubernetes.io/master=
    k8s-master13   Ready      master   27d   v1.15.1   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-master13,kubernetes.io/os=linux,node-role.kubernetes.io/master=
    k8s-master14   Ready      master   14d   v1.15.1   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-master14,kubernetes.io/os=linux,node-role.kubernetes.io/master=
    k8s-node01     Ready      pay      27d   v1.15.1   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-node01,kubernetes.io/os=linux,node-role.kubernetes.io/pay=,nodepool=pay
    k8s-node02     NotReady   ops      27d   v1.15.1   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-node02,kubernetes.io/os=linux,node-role.kubernetes.io/ops=
    
    
    kubectl edit deploy/nginx-test-v2配置nodeSelector
        spec:
          containers:
          - image: zzxng:v2
            imagePullPolicy: IfNotPresent
            name: zzxng-containers-v2
            resources: {}
            terminationMessagePath: /dev/termination-log
            terminationMessagePolicy: File
            volumeMounts:
            - mountPath: /etc/localtime
              name: mylocaltime
            - mountPath: /zzx
              name: mountdata
          dnsPolicy: ClusterFirst
          nodeSelector:
            nodepool: pay
    
    
    再拉新po就会到到lable为pay的计算节点
    View Code

    强制删除   kubectl delete pod    pod-name    --force --grace-period=0  

    [root@k8s-master12 ~]# kubectl delete pod nginx-deploy-v2-64ff9bdc9f-xx2tl --force --grace-period=0  
    warning: Immediate deletion does not wait for confirmation that the running resource has been terminated. The resource may continue to run on the cluster indefinitely.
    pod "nginx-deploy-v2-64ff9bdc9f-xx2tl" force deleted
    

    强制重启         kubectl get pod kube-flannel-ds-amd64-w9fr7 -n kube-system  -o yaml | kubectl replace --force -f -                 

    [root@k8s-master13 ~]# kubectl get pod kube-flannel-ds-amd64-w9fr7 -n kube-system  -o yaml | kubectl replace --force -f -                                    
    pod "kube-flannel-ds-amd64-w9fr7" deleted
    
    pod/kube-flannel-ds-amd64-w9fr7 replaced
    

      

    镜像保存、导出、导入          

    docker commit -a "www.zzx.com" -m "my nginx" f9469bf41fc8  zzxng:v2 
    docker save -o zzx_ng_v2.tar zzxng:v2
    docker  load -i zzx_ng_v2.tar
    [root@k8s-node02 ~]# docker ps                   
    CONTAINER ID   IMAGE                        COMMAND                  CREATED          STATUS                 PORTS                       NAMES
    f9469bf41fc8   54202d3f0f35                 "nginx -g 'daemon of…"   22 minutes ago   Up 22 minutes                                      k8s_myapp_nginx-m-585bdbdb-9kk44_default_f1fd4efb-4f06-4b22-bcbb-3f08a976a7d3_0
    78e32feff2c8   k8s.gcr.io/pause:3.1         "/pause"                 22 minutes ago   Up 22 minutes                                      k8s_POD_nginx-m-585bdbdb-9kk44_default_f1fd4efb-4f06-4b22-bcbb-3f08a976a7d3_0
    
    
    [root@k8s-node02 ~]# docker commit -a "www.zzx.com" -m "my nginx" f9469bf41fc8  zzxng:v2
    sha256:2d6de81dd78e24177ac22bea9aeaea3379373f24b036b7c791d9645b2a8e774c
    
    
    apply的时候image用   - image: zzxng:v2
    
    #导出镜像到文件  在scp给其他节点或者传到harbor
    [root@k8s-node02 ~]# docker save -o zzx_ng_v2.tar zzxng:v2
    [root@k8s-node02 ~]# ls -lrt zzx_ng_v2.tar
    -rw------- 1 root root 15921664 Apr 10 14:21 zzx_ng_v2.tar
    
    
    #导入
    [root@k8s-node01 ~]# docker  load -i zzx_ng_v2.tar
    
    35602d47c995: Loading layer [==================================================>]  13.31kB/13.31kB
    35602d47c995: Loading layer [==================================================>]  13.31kB/13.31kB
    
    [root@k8s-node01 ~]# docker images 
    REPOSITORY                                                       TAG             IMAGE ID       CREATED          SIZE
    zzxng                                                            v2              2d6de81dd78e   18 minutes ago   15.5MB
    

      master 设置taints(等号不能丢,为master设置的这个taint中, node-role.kubernetes.io/master为key, value为空, effect为NoSchedule)          effect:NoSchedule 一定不能被调度PreferNoSchedule 尽量不要调度 NoExecute   不仅不会调度, 还会驱逐Node上已有的Pod

    [root@k8s-master14 ~]# kubectl taint nodes  k8s-master13 node-role.kubernetes.io/master=:NoSchedule
    node/k8s-master13 tainted
    
    [root@k8s-master14 ~]# kubectl describe  node/k8s-master13|grep -i taint
    Taints:             node-role.kubernetes.io/master:NoSchedule
    View Code

     增加删除taint

    [root@k8s-master14 ~]# kubectl taint node k8s-node01 key1=value1:NoSchedule
    [root@k8s-master14 ~]# kubectl taint node k8s-node01 key1-

    nginx-ingress-controller添加容忍部署到master,添加完会自动把原来node01上的pod部署到master。

    tolerations:
    - key: "node-role.kubernetes.io/master"
      operator: "Equal"
      value: ""
      effect: "NoSchedule"
    View Code
    [root@k8s-master13 ~]# kubectl get pod -n ingress-nginx  -o wide
    NAME                                        READY   STATUS        RESTARTS   AGE    IP             NODE           NOMINATED NODE   READINESS GATES
    nginx-ingress-controller-56bb7fb667-8qzrx   1/1     Running       0          96s    10.244.4.60    k8s-master13   <none>           <none>
    nginx-ingress-controller-56bb7fb667-t42dp   1/1     Running       0          56s    10.244.5.6     k8s-master14   <none>           <none>
    nginx-ingress-controller-56bb7fb667-xg9kz   1/1     Running       0          118s   10.244.3.240   k8s-node01     <none>           <none>
    nginx-ingress-controller-75d98777f6-92lrh   0/1     Terminating   0          10m    10.244.3.238   k8s-node01     <none>           <none>
    [root@k8s-master13 ~]# kubectl get pod -n ingress-nginx  -o wide
    NAME                                        READY   STATUS    RESTARTS   AGE     IP             NODE           NOMINATED NODE   READINESS GATES
    nginx-ingress-controller-56bb7fb667-8qzrx   1/1     Running   0          4m11s   10.244.4.60    k8s-master13   <none>           <none>
    nginx-ingress-controller-56bb7fb667-t42dp   1/1     Running   0          3m31s   10.244.5.6     k8s-master14   <none>           <none>
    nginx-ingress-controller-56bb7fb667-xg9kz   1/1     Running   0          4m33s   10.244.3.240   k8s-node01     <none>           <none>
    View Code

     

      

  • 相关阅读:
    flink checkpoint机制的实现
    openjdk源码分析之AtomicLong
    cpp之宏和函数调用约定
    JNA 相关问题
    spark RDD
    最长连续序列
    买卖股票的最佳时机
    二叉树展开为链表
    不同的二叉搜索树
    柱状图中最大的矩形
  • 原文地址:https://www.cnblogs.com/hanxing/p/16123414.html
Copyright © 2020-2023  润新知