9. k8s集群搭建之通过label管理集群部署

  • 为node添加label:
    kubectl label nodes kube-node node=kube-node

  • 根据label筛选node:
    kubectl get node -a -l "node=kube-node"

  • 删除node label:
    kubectl label nodes test-node3 attach-

  • 根据label部署服务

apiVersion: v1
kind: ReplicationController
metadata:
 name: mongo
spec:
 replicas: 1 
 template:
   metadata:
     labels:
       run: mongo
   spec:
     containers:
     - name: mongo
       image: daocloud.io/library/mongo:3.2.4
       ports:
         - containerPort: 27017
       volumeMounts:
         - mountPath: /data/db
           name: mongo
     volumes: [{"name":"mongo","hostPath":{"path":"/root/volumes/mongo"}}]
     nodeSelector: 
       node: kube-node4