다음을 통해 공유


DaemonSet을 사용하여 작업자 노드 사용자 지정

애플리케이션 요구 사항을 충족하려면 운영 체제 설정을 수정하거나, Linux 커널 모듈을 사용하도록 설정하거나, 호스트 수준 애플리케이션 패키지를 설치해야 할 수 있습니다. 호스트 권한으로 DaemonSet를 사용하여 워커 노드를 사용자 지정할 수 있습니다.

이 예제DaemonSet에서는 이미지 다운로드 시 Cloud Services 네트워크 프록시를 우회하도록registry.contoso.com 설정하고, SCTP 커널 모듈을 설치하며, fs.inotify.max_user_instances4096로 설정합니다. 마지막으로 스크립트는 Kubernetes 노드에 레이블을 적용하여 DaemonSet이 한 번만 실행되도록 합니다.

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: customized
  namespace: kube-system
spec:
  selector:
    matchLabels:
      name: customized
  template:
    metadata:
      labels:
        name: customized
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                  - key: customized
                    operator: NotIn
                    values:
                      - "1"
      tolerations:
        - operator: Exists
          effect: NoSchedule
      containers:
        - name: customized
          image: mcr.microsoft.com/cbl-mariner/base/core:1.0
          command:
            - nsenter
            - --target
            - "1"
            - --mount
            - --uts
            - --ipc
            - --net
            - --pid
            - --
            - bash
            - -exc
            - |
              sed -i '/registrycontoso.com/!s/NO_PROXY=/&registry.contoso.com,/' /etc/systemd/system/containerd.service.d/http-proxy.conf
              systemctl daemon-reload
              systemctl restart containerd
              modprobe sctp
              sed -i 's/^fs.inotify.max_user_instances.*/fs.inotify.max_user_instances     = 4096/' /etc/sysctl.d/90-system-max-limits.conf
              kubectl --kubeconfig=/etc/kubernetes/kubelet.conf label node ${HOSTNAME,,} customized=1
              sleep infinity
          resources:
            limits:
              memory: 200Mi
            requests:
              cpu: 100m
              memory: 16Mi
          securityContext:
            privileged: true
      hostNetwork: true
      hostPID: true
      hostIPC: true
      terminationGracePeriodSeconds: 0

그리고 Daemonset을 적용합니다.

kubectl apply -f /path/to/daemonset.yaml