문제
The Kubelet on node01 shouldn't be able to set Node labels
starting with node-restriction.kubernetes.io/*
on other Nodes than itself
Verify this is not restricted atm by performing the following actions as the Kubelet from node01
🟢 분석하기
api-server의 구성 변경을 검증(제한)하는 admission 적용하는 방법에 대한 실습. node01과 controlplane 총 2대의 워커노드가 있고, node01에서는 controlplane의 노드 라벨을 추가할 수 없도록 하기
🟠 Step 1. [admission 적용 전] node01에서 node label 추가해보기 → 잘 작동함
controlplane $ ssh node01
Last login: Tue Jul 30 09:15:19 2024 from 10.244.6.54
node01 $ kubectl label node controlplane killercoda/one=123 # works but should be restricted
node/controlplane labeled
node01 $ kubectl label node node01 node-restriction.kubernetes.io/one=123 # works but should be restricted
node/node01 labeled
🟠 Step 2. 매니페스트를 수정해서 static pod(kube-apiserver) 장애 발생시키기
아래 명령으로 kube-apiserver 편집, `spec.containers.command`에 `--enable-admission-plugins=NodeRestriction` 옵션 추가하기
# controlplane 노드에서 실행
vi /etc/kubernetes/manifests/kube-apiserver.yaml
---
spec:
containers:
- command:
- kube-apiserver
- --advertise-address=172.30.1.2
... 중략 ...
- --enable-admission-plugins=NodeRestriction
node01에 접속해서 라벨 수정 해보기 → node01 외 다른 노드는 label 추가 안됨
🟢 결론
아래 홈페이지를 가보면 api-server의 addmission을 사용해 여러가지 활동에 대한 제약을 줄 수 있음을 알 수 있습니다. 이번 실습에서 자용한 addmission은 `NodeRestriction`입니다. 설명 중 일부를 발췌 해보면 해당 옵션은 검증 작업을 수행하는 옵션이고, Node 및 Pod API 호출 시 요청자 kubelet이 설치된 노드에서만 수정을 허용하는 옵션임을 알 수 있습니다.
Such kubelets will only be allowed to modify their own Node API object, and only modify Pod API objects that are bound to their node.
Admission Controllers Reference
This page provides an overview of Admission Controllers. What are they? An admission controller is a piece of code that intercepts requests to the Kubernetes API server prior to persistence of the object, but after the request is authenticated and authoriz
kubernetes.io
'클라우드' 카테고리의 다른 글
[O-Tel] Opentelemetry로 .Net Trace 구성하기 (1) | 2024.10.12 |
---|---|
[cks][killershell] Auditing Enable Audit Logging 실습 (0) | 2024.07.31 |
[cks][killershell] Apiserver Crash 실습 (0) | 2024.07.29 |
[EKS] IaC (0) | 2024.04.27 |
[k8s] Pod의 전략적 배치 - Node Affinity (0) | 2024.04.17 |