カスタム kube-dns Deployment の設定


このページでは、Google Kubernetes Engine(GKE)Standard モードのクラスタで kube-dns のカスタム Deployment を実行する方法について説明します。このページは、Google が kube-dns を管理する GKE Autopilot には適用されません。

概要

kube-dns CPU、メモリ、その他のパラメータを構成するには、カスタム Deployment を実行し、GKE が提供する Deployment を無効にする必要があります。このページの手順に沿って、Core DNS または Kubernetes DNS 仕様を遵守したその他の DNS プロバイダのカスタム Deployment を実行することもできます。

GKE がサービス ディスカバリを実装する方法の詳細については、サービス ディスカバリと DNS をご覧ください。

カスタム Deployment の作成

  1. kube-dns、Core DNS、またはその他の DNS プロバイダの Deployment マニフェストを作成します。

    次の kube-dns マニフェストのサンプルには、クエリの結果をロギングする -q フラグが含まれています。マニフェストを custom-kube-dns.yaml として保存します。

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: DNS_DEPLOYMENT_NAME
      namespace: kube-system
      annotations:
        deployment.kubernetes.io/revision: "1"
        k8s-app: kube-dns
    spec:
      selector:
        matchLabels:
          k8s-app: kube-dns
      strategy:
        rollingUpdate:
          maxSurge: 10%
          maxUnavailable: 0
        type: RollingUpdate
      template:
        metadata:
          creationTimestamp: null
          labels:
            k8s-app: kube-dns
        spec:
          containers:
          - name: kubedns
            image: registry.k8s.io/dns/k8s-dns-kube-dns:1.17.3
            resources:
              limits:
                memory: '170Mi'
              requests:
                cpu: 100m
                memory: '70Mi'
            livenessProbe:
              httpGet:
                path: /healthcheck/kubedns
                port: 10054
                scheme: HTTP
              initialDelaySeconds: 60
              timeoutSeconds: 5
              successThreshold: 1
              failureThreshold: 5
            readinessProbe:
              httpGet:
                path: /readiness
                port: 8081
                scheme: HTTP
              initialDelaySeconds: 3
              timeoutSeconds: 5
            args:
            - --domain=cluster.local.
            - --dns-port=10053
            - --config-dir=/kube-dns-config
            - --v=2
            env:
            - name: PROMETHEUS_PORT
              value: "10055"
            ports:
            - containerPort: 10053
              name: dns-local
              protocol: UDP
            - containerPort: 10053
              name: dns-tcp-local
              protocol: TCP
            - containerPort: 10055
              name: metrics
              protocol: TCP
            volumeMounts:
            - name: kube-dns-config
              mountPath: /kube-dns-config
            securityContext:
              allowPrivilegeEscalation: false
              readOnlyRootFilesystem: true
              runAsUser: 1001
              runAsGroup: 1001
          - name: dnsmasq
            image: registry.k8s.io/dns/k8s-dns-dnsmasq-nanny:1.17.3
            livenessProbe:
              httpGet:
                path: /healthcheck/dnsmasq
                port: 10054
                scheme: HTTP
              initialDelaySeconds: 60
              timeoutSeconds: 5
              successThreshold: 1
              failureThreshold: 5
            args:
            - -v=2
            - -logtostderr
            - -configDir=/etc/k8s/dns/dnsmasq-nanny
            - -restartDnsmasq=true
            - --
            - -k
            - --cache-size=1000
            - --no-negcache
            - --dns-forward-max=1500
            - --log-facility=-
            - --server=/cluster.local/127.0.0.1#10053
            - --server=/in-addr.arpa/127.0.0.1#10053
            - --server=/ip6.arpa/127.0.0.1#10053
            ports:
            - containerPort: 53
              name: dns
              protocol: UDP
            - containerPort: 53
              name: dns-tcp
              protocol: TCP
            resources:
              requests:
                cpu: 150m
                memory: 20Mi
            volumeMounts:
            - name: kube-dns-config
              mountPath: /etc/k8s/dns/dnsmasq-nanny
            securityContext:
              capabilities:
                drop:
                - all
                add:
                - NET_BIND_SERVICE
                - SETGID
          - name: sidecar
            image: registry.k8s.io/dns/k8s-dns-sidecar:1.17.3
            livenessProbe:
              httpGet:
                path: /metrics
                port: 10054
                scheme: HTTP
              initialDelaySeconds: 60
              timeoutSeconds: 5
              successThreshold: 1
              failureThreshold: 5
            args:
            - --v=2
            - --logtostderr
            - --probe=kubedns,127.0.0.1:10053,kubernetes.default.svc.cluster.local,5,SRV
            - --probe=dnsmasq,127.0.0.1:53,kubernetes.default.svc.cluster.local,5,SRV
            ports:
            - containerPort: 10054
              name: metrics
              protocol: TCP
            resources:
              requests:
                memory: 20Mi
                cpu: 10m
            securityContext:
              allowPrivilegeEscalation: false
              readOnlyRootFilesystem: true
              runAsUser: 1001
              runAsGroup: 1001
          dnsPolicy: Default
          restartPolicy: Always
          schedulerName: default-scheduler
          securityContext: {}
          serviceAccount: kube-dns
          serviceAccountName: kube-dns
          terminationGracePeriodSeconds: 30
          tolerations:
          - key: CriticalAddonsOnly
            operator: Exists
          volumes:
          - configMap:
              defaultMode: 420
              name: kube-dns
              optional: true
            name: kube-dns-config
    

    DNS_DEPLOYMENT_NAME をカスタム kube-dns Deployment の名前に置き換えます。

  2. マニフェストをクラスタに適用します。

    kubectl create -f custom-kube-dns.yaml
    
  3. Pod が実行されていることを確認します。

    kubectl get pods -n kube-system -l=k8s-app=kube-dns
    

    カスタム kube-dns Pod を示す出力は次のようになります。

    NAME                               READY   STATUS    RESTARTS   AGE
    custom-kube-dns-5685645b44-kzs8w   3/3     Running   0          22h
    

    新しい Deployment のセレクタは kube-dns と同じです。つまり、Pod は同じ kube-dns サービス IP アドレスを使用して、カスタム kube-dns Deployment を実行している Pod と通信します。

    このステップを完了したら、次のセクションの手順に沿って kube-dns をスケールダウンする必要があります。

kube-dns のスケールダウン

次のコマンドを使用して、kube-dns Deployment とオートスケーラーをゼロにスケーリングし、GKE が管理する kube-dns を無効にします。

kubectl scale deployment --replicas=0 kube-dns-autoscaler --namespace=kube-system
kubectl scale deployment --replicas=0 kube-dns --namespace=kube-system

カスタム オートスケーラーの作成

カスタム DNS で自動スケーリングが必要な場合は、個別のオートスケーラーを構成してデプロイする必要があります。kube-dns-autoscaler は、クラスタ上のデフォルトの kube-dns Deployment のみをスケーリングします。また、オートスケーラーにカスタム ClusterRole を構成し、カスタム kube-dns デプロイを変更する権限を追加する必要もあります。

  1. オートスケーラーの ClusterRole および Deployment マニフェストを作成し、マニフェストを custom-dns-autoscaler.yaml として保存します。

    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRoleBinding
    metadata:
      name: system:custom-dns-autoscaler
    roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: ClusterRole
      name: system:custom-dns-autoscaler
    subjects:
    - kind: ServiceAccount
      name: kube-dns-autoscaler
      namespace: kube-system
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRole
    metadata:
      name: system:custom-dns-autoscaler
    rules:
    - apiGroups:
      - ""
      resources:
      - nodes
      verbs:
      - list
      - watch
    - apiGroups:
      - apps
      resourceNames:
      - DNS_DEPLOYMENT_NAME
      resources:
      - deployments/scale
      verbs:
      - get
      - update
    - apiGroups:
      - ""
      resources:
      - configmaps
      verbs:
      - get
      - create
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: custom-dns-autoscaler
      namespace: kube-system
      labels:
        k8s-app: custom-dns-autoscaler
    spec:
      selector:
        matchLabels:
          k8s-app: custom-dns-autoscaler
      template:
        metadata:
          labels:
            k8s-app: custom-dns-autoscaler
          annotations:
            seccomp.security.alpha.kubernetes.io/pod: 'docker/default'
        spec:
          priorityClassName: system-cluster-critical
          securityContext:
            supplementalGroups: [ 65534 ]
            fsGroup: 65534
          nodeSelector:
            kubernetes.io/os: linux
          containers:
          - name: autoscaler
            image: registry.k8s.io/cluster-proportional-autoscaler-amd64:1.7.1
            resources:
                requests:
                    cpu: "20m"
                    memory: "10Mi"
            command:
              - /cluster-proportional-autoscaler
              - --namespace=kube-system
              - --configmap=custom-dns-autoscaler
              - --target=Deployment/DNS_DEPLOYMENT_NAME
              - --default-params={"linear":{"coresPerReplica":256,"nodesPerReplica":16,"preventSinglePointFailure":true}}
              - --logtostderr=true
              - --v=2
          tolerations:
          - key: "CriticalAddonsOnly"
            operator: "Exists"
          serviceAccountName: kube-dns-autoscaler
    
  2. マニフェストをクラスタに適用します。

    kubectl create -f custom-dns-autoscaler.yaml
    

次のステップ