k8s固定pod在某一节点, node添加Label

基本信息

服务器: kubernetes-master-1, kubernetes-node-1, kubernetes-node-2

容器: mysql-master

配置文件: MySQL.yml

###### 省略 ######
spec:
  replicas: 1
  selector:
    matchLabels:
      name: mysql-master
  template:
    metadata:
      labels:
        name: mysql-master
    spec:
      containers:
        - name: mysql-master
          image: XXXX
          imagePullPolicy: IfNotPresent
###### 省略 ######

现在希望mysql-master能共固定在kubernetes-node-1上;

 

master-1服务器上操作

查看现有node及label:  kubectl get node --show-labels

添加label: kubectl label nodes = 

kubectl label nodes kubernetes-node-1 name=node-1

删除label: kubectl label nodes

修改Label的值: kubectl label nodes = --overwrite
 

添加之后查看现有node及label: 

 

修改配置文件: vim MySQL.yml

###### 省略 ######
spec:
  replicas: 1
  selector:
    matchLabels:
      name: mysql-master
  template:
    metadata:
      labels:
        name: mysql-master
    spec:
      nodeSelector:
          name: "node-1"  # :  
      containers:
        - name: mysql-master
          image: XXXX
          imagePullPolicy: IfNotPresent
###### 省略 ######

重新应用一下: kubectl apply -f MySQL.yml

完成

你可能感兴趣的:(k8s固定pod在某一节点, node添加Label)