一看必會系列:k8s 練習5 k8s調度給指定node

來源:本站原創 Kubernetes 超過285 views圍觀 0條評論

 

查看當前node2信息
[[email protected] elk]#  kubectl describe node k8s-node2 |grep -C 5 Lab
Name:               k8s-node2
Roles:              <none>
Labels:             beta.kubernetes.io/arch=amd64
                    beta.kubernetes.io/os=linux
                    kubernetes.io/hostname=k8s-node2
Annotations:        flannel.alpha.coreos.com/backend-data: {"VtepMAC":"3e:27:fd:0f:47:76"}
                    flannel.alpha.coreos.com/backend-type: vxlan
                    flannel.alpha.coreos.com/kube-subnet-manager: true
[[email protected] elk]#

1.來打個標 

命令如下 kubectl label nodes node名 隨便寫=隨便寫1

[[email protected] elk]# kubectl label nodes k8s-node2 mylabel=100
node/k8s-node2 labeled
[[email protected] elk]#  kubectl describe node k8s-node2 |grep -C 10 Lab
Name:               k8s-node2
Roles:              <none>
Labels:             beta.kubernetes.io/arch=amd64
                    beta.kubernetes.io/os=linux
                    kubernetes.io/hostname=k8s-node2
                    mylabel=100    #〈--就是這個東西
Annotations:        flannel.alpha.coreos.com/backend-data: {"VtepMAC":"3e:27:fd:0f:47:76"}
                    flannel.alpha.coreos.com/backend-type: vxlan
                    flannel.alpha.coreos.com/kube-subnet-manager: true
                    flannel.alpha.coreos.com/public-ip: 192.168.10.71
                    kubeadm.alpha.kubernetes.io/cri-socket: /var/run/dockershim.sock
                    node.alpha.kubernetes.io/ttl: 0
                    volumes.kubernetes.io/controller-managed-attach-detach: true
[[email protected] elk]#

2.難后搞個容器試試
vim busybox-pod5.yaml
apiVersion: v1
kind: Pod
metadata:
  name: busybox-testxx4
  labels:
    name: busybox-pod-lb
spec:
  containers:
  – name: busybox-xxx4
    image: reg.ccie.wang/library/busybox:1.30.1
    command:
    – sleep
    – "3600"
  #使用下面命令進行node選擇
  nodeSelector:
    mylabel: "100"

創建
kubectl apply -f busybox-pod5.yaml

驗證

[[email protected] busybox]# kubectl get pod -o wide
NAME                       READY   STATUS    RESTARTS   AGE    IP             NODE        NOMINATED NODE   READINESS GATES
busybox-testxx4            1/1     Running   0          54s    10.244.2.88   k8s-node2   <none>           <none>
可以看到node2 上面去了

查看pod信息
[[email protected] busybox]# kubectl describe pod busybox-testxx4
Name:               busybox-testxx4
Labels:             name=busybox-pod-lb
IP:                 10.244.2.88
Containers:
  busybox-xxx4:
    Image:         reg.ccie.wang/library/busybox:1.30.1
    Command:
      sleep
      3600
      #新標標
Node-Selectors:  mylabel=100

Events:
  Type    Reason     Age    From                Message
  —-    ——     —-   —-                ——-
  Normal  Scheduled  4m17s  default-scheduler   Successfully assigned default/busybox-testxx4 to k8s-node2
  Normal  Pulled     4m16s  kubelet, k8s-node2  Container image "reg.ccie.wang/library/busybox:1.30.1" already present on machine
  Normal  Created    4m16s  kubelet, k8s-node2  Created container
  Normal  Started    4m16s  kubelet, k8s-node2  Started container
[[email protected] busybox]#

 

 

 

————報錯  沒起來
[[email protected] busybox]# kubectl get pod -o wide
NAME                       READY   STATUS        RESTARTS   AGE    IP             NODE        NOMINATED NODE   READINESS GATES
busybox-testxx1            0/1     Pending       0          38m    <none>         k8s-node2   <none>           <none>

[[email protected] busybox]# kubectl describe pod busybox-testxx1
Name:               busybox-testxx1
Namespace:          default
Priority:           0
PriorityClassName:  <none>
Node:               k8s-node2/
Labels:             name=busybox-pod-lb
Annotations:        <none>
Status:             Pending
IP:                
Containers:
  busybox-xxx1:
    Image:        busybox
Node-Selectors:  mylabel=100

Events:
  Type     Reason     Age                   From                Message
  —-     ——     —-                  —-                ——-
  Normal   Scheduled  3m32s                 default-scheduler   Successfully assigned default/busybox-testxx5 to k8s-node2
  Normal   Pulled     113s (x5 over 3m31s)  kubelet, k8s-node2  Container image "reg.ccie.wang/library/busybox:1.30.1" already present on machine
  Normal   Created    113s (x5 over 3m30s)  kubelet, k8s-node2  Created container
  Normal   Started    113s (x5 over 3m30s)  kubelet, k8s-node2  Started container
  Warning  BackOff    99s (x10 over 3m28s)  kubelet, k8s-node2  Back-off restarting failed container

對于像ubuntu這樣的系統級docker ,用k8s集群啟動管理后,會自動關閉,
解決方法就是 讓其一直在運行,所以在yaml文件中增加command命令即可

原因是這里配錯了
apiVersion: v1
kind: Pod
metadata:
  name: busybox-testxx1
  labels:
    name: busybox-pod-lb
spec:
  containers:
  – name: busybox-xxx1
    image: busybox
#需要增加命令3條
    command:
    – sleep
    – "3600"

  nodeSelector:
    mylabel: "100"
   
   
或者只要有進程運行就行。
     command: [ "/bin/bash", "-c", "–" ]
     args: [ "while true; do sleep 30; done;" ]

文章出自:CCIE那點事 http://www.qdxgqk.live/ 版權所有。本站文章除注明出處外,皆為作者原創文章,可自由引用,但請注明來源。 禁止全文轉載。
本文鏈接:http://www.qdxgqk.live/?p=4126轉載請注明轉自CCIE那點事
如果喜歡:點此訂閱本站
  • 相關文章
  • 為您推薦
  • 各種觀點
?
暫時還木有人評論,坐等沙發!
發表評論

您必須 [ 登錄 ] 才能發表留言!

?
?
萌宠夺宝游戏 最准二肖中特 七星彩预测最准号码 重庆时时彩网 安卓手机挂机赚钱app6 真钱手机斗地主 彩票18选7开奖号查询 河南快三开奖走势一定 不需要赚钱费用的银行 财神捕鱼电玩 七乐彩走势图怎么看 街机电玩捕鱼兑话费 足彩胜负彩分析软件 十一运夺金开奖走势图 七乐彩杀号专家 陕西快乐十分电视版 乐天国际群