Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Übersicht
In diesem Dokument wird gezeigt, wie Sie ein privilegiertes DaemonSet auf jedem Knoten einer Google Distributed Cloud bereitstellen können, um kubelet-Parameter für die Aktivierung schreibgeschützter Ports zu ändern. In Version 1.16 und höher ist der schreibgeschützte Port für Kubelet standardmäßig deaktiviert.
Voraussetzung
Prüfen Sie, ob Google Distributed Cloud fehlerfrei ist, bevor Sie Folgendes patch-Skript ausführen. Sie können diese Lösung verwenden, um Administratorcluster und Nutzercluster der Version 1.16 zu patchen.
DaemonSet-Datei erstellen
Erstellen und speichern Sie eine DaemonSet-Datei namens patch.yaml in Ihrem aktuellen Verzeichnis mit folgendem Inhalt:
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"
Schreibgeschützte Portnummer aktualisieren
Bearbeiten Sie die Umgebungsvariable KUBELET_READONLY_PORT in der DaemonSet-YAML-Datei manuell, um die Portnummer zu ändern.
Der schreibgeschützte Standardport ist 10255. Sie sollten 10250 nicht auswählen, da dies mit dem vordefinierten sicheren Port in Konflikt steht.
Bearbeiten Sie die Umgebungsvariable KUBELET_READONLY_PORT in der DaemonSet-YAML-Datei manuell, um den schreibgeschützten Port zu deaktivieren.
Nachdem Sie die Änderungen gespeichert haben, wird das DaemonSet noch einmal ausgeführt, um das Kubelet entsprechend zu ändern.
Vorsichtsmaßnahmen
Dieser Patch hat den gleichen Lebenszyklus wie Ihre installierten Drittanbieter-Apps. Sie können ihn jeder Zeit als Day-2-Vorgang ausführen. Er bleibt aber möglicherweise nicht bestehen, nachdem Sie den Cluster neu erstellt haben. Stellen Sie dieses DaemonSet als Schritt im "Post-Initialisierungs"-Vorgang von Google Distributed Cloud bereit.
Nach der einmaligen Ausführung sollte die kubelet-Konfigurationsdatei geändert und neu geladen werden. Sie können kubectl delete -f patch.yaml sicher ausführen, um eine Bereinigung der DaemonSet-Ressourcen durchzuführen.
Google Distributed Cloud unter Windows unterstützt diesen Patch nicht.
Kubernetes führt auf diesem unsicheren Port 10255 keine Authentifizierungs- oder Autorisierungsprüfungen durch. Durch die Aktivierung bleiben kubelet-Daten ungeschützt und nicht autorisierten Nutzern ausgesetzt. Das Kubelet stellt denselben Endpunkt auf dem sichereren, authentifizierten Port 10250 bereit. Sie sollten zu diesem sicheren Port migrieren.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 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."]]