이 문서에서는 Google Distributed Cloud의 각 노드에 권한이 있는 DaemonSet를 배포하여 읽기 전용 포트를 사용 설정하도록 kubelet 매개변수를 수정하는 방법을 설명합니다. 버전 1.16 이상에서는 kubelet 읽기 전용 포트가 기본적으로 사용 중지됩니다.
기본 요건
다음 패치 스크립트를 실행하기 전에 Google Distributed Cloud가 정상인지 확인합니다. 이 솔루션을 사용하여 1.16 이상인 관리자 클러스터 및 사용자 클러스터를 패치할 수 있습니다.
DaemonSet 파일 만들기
다음 콘텐츠로 현재 디렉터리에 patch.yaml이라는 DaemonSet 파일을 만들고 저장합니다.
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: "10255"
# 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: '"${readonlyport}"'/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"
읽기 전용 포트 번호 업데이트
포트 번호를 변경하려면 DaemonSet YAML에서 환경 변수 KUBELET_READONLY_PORT를 수동으로 수정합니다.
기본 읽기 전용 포트는 10255입니다. 10250은 사전 정의된 보안 포트와 충돌하므로 선택하지 마세요.
읽기 전용 포트를 사용 중지하려면 DaemonSet YAML에서 환경 변수 KUBELET_READONLY_PORT를 수동으로 수정하세요.
변경사항을 저장하면 DaemonSet가 다시 실행되어 kubelet을 수정합니다.
주의사항
이 패치는 설치된 제3자 앱과 동일한 수명 주기를 갖습니다. 2일 차 작업으로 언제든지 실행할 수 있습니다. 하지만 클러스터를 다시 만든 후에는 유지되지 않을 수 있습니다. 이 변경사항을 영구적으로 유지하려면 Google Distributed Cloud 초기화 후 작업에서 이 DaemonSet를 배포합니다.
한 번 실행한 후에 Kubelet 구성 파일을 수정하고 새로고침해야 합니다. kubectl delete -f patch.yaml을 안전하게 실행하여 DaemonSet 리소스를 삭제할 수 있습니다.
Windows에서 실행되는 Google Distributed Cloud는 이 패치를 지원하지 않습니다.
Kubernetes는 이 안전하지 않은 포트 10255에서 인증 또는 승인 검사를 수행하지 않습니다. 사용 설정하면 kubelet 데이터는 보호되지 않으며 승인되지 않은 사용자에게 노출됩니다. kubelet은 보다 안전하고 인증된 포트 10250에서 동일한 엔드포인트를 제공합니다. 해당 보안 포트로 마이그레이션하는 것이 좋습니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-01(UTC)"],[],[],null,["Overview\n\nThis document shows how to deploy a privileged DaemonSet in each node of\nGoogle Distributed Cloud to modify kubelet parameters to enable\nread-only ports. In version 1.16 and later, the kubelet read-only port is\ndisabled by default.\n\nPrerequisite\n\nMake sure your Google Distributed Cloud is healthy before running the following\npatch script. You can use this solution to patch 1.16 and later admin clusters\nand user clusters.\n\nCreate a DaemonSet file\n\nCreate and save a DaemonSet file named patch.yaml in your current directory,\nwith the following content:\n\n```\napiVersion: apps/v1\nkind: DaemonSet\nmetadata:\n name: onprem-node-patcher\n namespace: kube-system\nspec:\n selector:\n matchLabels:\n name: onprem-node-patcher\n updateStrategy:\n type: RollingUpdate\n template:\n metadata:\n labels:\n name: onprem-node-patcher\n spec:\n tolerations:\n - operator: Exists\n volumes:\n - name: host\n hostPath:\n path: /\n hostPID: true\n initContainers:\n - name: read-only-patcher\n image: \"ubuntu\"\n env:\n - name: KUBELET_READONLY_PORT\n value: \"10255\"\n # Number of 1G hugepages. Update the value as desired.\n command:\n - /bin/bash\n - -c\n - |\n set -xeuo pipefail\n configfile=\"/host/var/lib/kubelet/config.yaml\"\n kubeletservice=\"/host/etc/systemd/system/kubelet.service\"\n # $1: The read-only port for the kubelet to serve on with no\n # authentication/authorization (set to 0 to disable)\n function set-readonly-port-in-config() {\n [[ \"$#\" -eq 1 ]] || return\n local readonlyport; readonlyport=\"$1\"\n local actual; actual=\"$(grep readOnlyPort \"${configfile}\")\"\n if [[ \"${actual}\" == \"\" ]]; then\n echo \"readOnlyPort: ${readonlyport}\" \u003e\u003e \"${configfile}\"\n else\n sed -E -i 's/readOnlyPort: [0-9]+/readOnlyPort: '\"${readonlyport}\"'/g' ${configfile}\n fi\n echo \"Successfully append readOnlyPort: ${readonlyport} to ${configfile}\"\n }\n sed -E -i 's/--read-only-port=[0-9]+/--read-only-port='\"${KUBELET_READONLY_PORT}\"'/g' ${kubeletservice}\n [[ -f ${configfile} ]] && set-readonly-port-in-config \"${KUBELET_READONLY_PORT}\"\n echo \"Restarting kubelet...\"\n chroot /host nsenter -a -t1 -- systemctl daemon-reload\n chroot /host nsenter -a -t1 -- systemctl restart kubelet.service\n echo \"Success!\"\n volumeMounts:\n - name: host\n mountPath: /host\n resources:\n requests:\n memory: 5Mi\n cpu: 5m\n securityContext:\n privileged: true\n containers:\n - image: gcr.io/google-containers/pause:3.2\n name: pause\n # Ensures that the pods will only run on the nodes having the correct\n # label.\n nodeSelector:\n \"kubernetes.io/os\": \"linux\"\n```\n\nUpdate the read-only port number\n\n- To change the port number, manually edit the environment variable `KUBELET_READONLY_PORT` in the DaemonSet YAML.\n\n- The default read-only port is `10255`, you should not pick `10250` as it will conflict with the predefined secure port.\n\nPatch the admin cluster\n\n```\n kubectl apply -f patch.yaml \\\n --kubeconfig ADMIN_CLUSTER_KUBECONFIG\n```\n\nPatch the user cluster\n\n```\n kubectl apply -f patch.yaml \\\n --kubeconfig USER_CLUSTER_KUBECONFIG\n```\n\nRestore\n\n- To disable the read-only port, manually edit the environment variable\n `KUBELET_READONLY_PORT` in the DaemonSet YAML.\n\n- After you save the changes, the DaemonSet will be re-run to modify the kubelet\n accordingly.\n\nCaveats\n\n- This patch has the same lifecycle as your installed 3P apps. You can run it\n anytime as a day 2 operation. But it might not persist after you re-create\n the cluster. To make this change persistent, deploy this DaemonSet as a step\n in the Google Distributed Cloud post-initialization action.\n\n- After running once, the kubelet configuration file should be modified and\n reloaded. You can safely run `kubectl delete -f patch.yaml` to clean up\n DaemonSet resources.\n\n- Google Distributed Cloud running on Windows does not support this patch.\n\n- Kubernetes does not perform any authentication or authorization checks on this\n insecure port `10255`. Enabling it will leave kubelet data unprotected and\n exposed to unauthorized users. The kubelet serves the same endpoint on the\n more secure, authenticated port `10250`, consider migrating to that secure\n port."]]