개요
이 문서에서는 VMware용 GKE의 각 노드에 권한이 있는 daemonset를 배포하여 읽기 전용 포트를 사용 중지하도록 kubelet 매개변수를 수정하는 방법을 설명합니다.
기본 요건
다음 패치 스크립트를 실행하기 전에 VMware용 GKE가 정상인지 확인합니다. 이 솔루션은 관리자 클러스터 및 사용자 클러스터에 패치를 적용하는 데 사용할 수 있습니다. 또한 모든 버전의 VMware용 GKE에서 작동합니다.
다음 Daemonset YAML을 로컬 파일에 저장합니다(예: patch.yaml).
apiVersion: apps/v1 kind: DaemonSet metadata: name: onprem-node-patcher namespace: kube-system spec: selector: matchLabels: name: onprem-node-patcher updateStrategy: type: RollingUpdate template: metadata: labels: name: onprem-node-patcher spec: tolerations: - operator: Exists volumes: - name: host hostPath: path: / hostPID: true initContainers: - name: read-only-patcher image: "ubuntu" env: - name: KUBELET_READONLY_PORT value: "0" # Number of 1G hugepages. Update the value as desired. command: - /bin/bash - -c - | set -xeuo pipefail configfile="/host/var/lib/kubelet/config.yaml" kubeletservice="/host/etc/systemd/system/kubelet.service" # $1: The read-only port for the kubelet to serve on with no # authentication/authorization (set to 0 to disable) function set-readonly-port-in-config() { [[ "$#" -eq 1 ]] || return local readonlyport; readonlyport="$1" local actual; actual="$(grep readOnlyPort "${configfile}")" if [[ "${actual}" == "" ]]; then echo "readOnlyPort: ${readonlyport}" >> "${configfile}" else sed -E -i 's/readOnlyPort: [0-9]+/readOnlyPort: 0/g' ${configfile} fi echo "Successfully append readOnlyPort: ${readonlyport} to ${configfile}" } sed -E -i 's/--read-only-port=[0-9]+/--read-only-port='"${KUBELET_READONLY_PORT}"'/g' ${kubeletservice} [[ -f ${configfile} ]] && set-readonly-port-in-config "${KUBELET_READONLY_PORT}" echo "Restarting kubelet..." chroot /host nsenter -a -t1 -- systemctl daemon-reload chroot /host nsenter -a -t1 -- systemctl restart kubelet.service echo "Success!" volumeMounts: - name: host mountPath: /host resources: requests: memory: 5Mi cpu: 5m securityContext: privileged: true containers: - image: gcr.io/google-containers/pause:3.2 name: pause # Ensures that the pods will only run on the nodes having the correct # label. nodeSelector: "kubernetes.io/os": "linux"
관리자 클러스터에 패치 적용
kubectl apply -f patch.yaml \ --kubeconfig ADMIN_CLUSTER_KUBECONFIG
사용자 클러스터에 패치 적용
kubectl apply -f patch.yaml \ --kubeconfig USER_CLUSTER_KUBECONFIG
복원
읽기 전용 포트를 다시 사용 설정하려면 Daemonset YAML에서 환경 변수
KUBELET_READONLY_PORT
를 수동으로 수정하세요.변경사항을 저장하면 daemonset가 다시 실행되어 kubelet을 수정합니다.
주의사항
이 패치는 설치된 제3자 앱과 동일한 수명 주기를 갖습니다. 2일 차 작업으로 언제든지 실행할 수 있습니다. 하지만 클러스터를 다시 만든 후에는 유지되지 않을 수 있습니다. 이 변경사항을 영구적으로 유지하려면 VMware용 GKE 초기화 후 작업에서 이 daemonset를 배포합니다.
한 번 실행한 후에 Kubelet 구성 파일을 수정하고 새로고침해야 합니다.
kubectl delete -f patch.yaml
을 안전하게 실행하여 daemonset 리소스를 삭제할 수 있습니다.Windows에서 실행되는 Anthos는 현재 이 패치를 지원하지 않습니다.
클러스터 버전 1.13 이하에서는 다음 측정항목이 보존되지 않습니다.