使用Kops创建的集群 - 使用DaemonSet按节点部署一个pod,从而避免使用主节点

时间:2017-02-09 10:42:39

标签: kubernetes

我尝试按节点部署一个pod。它适用于种类daemonSet以及使用kubeup创建集群时。但我们使用kops迁移了集群创建,而使用kops,主节点是集群的一部分。

我注意到主节点是使用特定标签定义的:kubernetes.io/role=master

并带有污点:scheduler.alpha.kubernetes.io/taints:[{"key":"dedicated","value":"master","effect":"NoSchedule"}]

但是,使用DaemonSet

在其上部署了一个pod并没有停止

所以我尝试添加scheduler.alpha.kubernetes.io/affinity

- apiVersion: extensions/v1beta1
  kind: DaemonSet
  metadata:
    name: elasticsearch-data
    namespace: ess
    annotations:
      scheduler.alpha.kubernetes.io/affinity: >
        {
          "nodeAffinity": {
            "requiredDuringSchedulingRequiredDuringExecution": {
              "nodeSelectorTerms": [
                {
                  "matchExpressions": [
                    {
                      "key": "kubernetes.io/role",
                      "operator": "NotIn",
                      "values": ["master"]
                    }
                  ]
                }
              ]
            }
          }
        }
  spec:
    selector:
      matchLabels:
        component: elasticsearch
        type: data
        provider: fabric8
    template:
      metadata:
        labels:
          component: elasticsearch
          type: data
          provider: fabric8
      spec:
        serviceAccount: elasticsearch
        serviceAccountName: elasticsearch
        containers:
          - env:
              - name: "SERVICE_DNS"
                value: "elasticsearch-cluster"
              - name: "NODE_MASTER"
                value: "false"
            image: "essearch/ess-elasticsearch:1.7.6"
            name: elasticsearch
            imagePullPolicy: Always
            ports:
              - containerPort: 9300
                name: transport
            volumeMounts:
              - mountPath: "/usr/share/elasticsearch/data"
                name: task-pv-storage
        volumes:
          - name: task-pv-storage
            persistentVolumeClaim:
              claimName: task-pv-claim
        nodeSelector:
          minion: true

但它不起作用。有人知道为什么吗? 我现在的解决方法是使用nodeSelector并向仅为minion的节点添加标签,但我会避免在群集创建期间添加标签,因为这是一个额外的步骤,如果我可以避免它,它将是最好的:))

修改

我改为那个(给出答案),我认为这是正确的,但它没有帮助,我仍然部署了一个吊舱:

- apiVersion: extensions/v1beta1
  kind: DaemonSet
  metadata:
    name: elasticsearch-data
    namespace: ess
  spec:
    selector:
      matchLabels:
        component: elasticsearch
        type: data
        provider: fabric8
    template:
      metadata:
        labels:
          component: elasticsearch
          type: data
          provider: fabric8
        annotations:
          scheduler.alpha.kubernetes.io/affinity: >
            {
              "nodeAffinity": {
                "requiredDuringSchedulingRequiredDuringExecution": {
                  "nodeSelectorTerms": [
                    {
                      "matchExpressions": [
                        {
                          "key": "kubernetes.io/role",
                          "operator": "NotIn",
                          "values": ["master"]
                        }
                      ]
                    }
                  ]
                }
              }
            }
      spec:
        serviceAccount: elasticsearch
        serviceAccountName: elasticsearch
        containers:
          - env:
              - name: "SERVICE_DNS"
                value: "elasticsearch-cluster"
              - name: "NODE_MASTER"
                value: "false"
            image: "essearch/ess-elasticsearch:1.7.6"
            name: elasticsearch
            imagePullPolicy: Always
            ports:
              - containerPort: 9300
                name: transport
            volumeMounts:
              - mountPath: "/usr/share/elasticsearch/data"
                name: task-pv-storage
        volumes:
          - name: task-pv-storage
            persistentVolumeClaim:
              claimName: task-pv-claim

1 个答案:

答案 0 :(得分:0)

只需将注释移到 pod template:部分(metadata:下)。

或者taint主节点(您可以删除注释):

kubectl taint nodes nameofmaster dedicated=master:NoSchedule

我建议你阅读taints and tolerations