"Killer Shell CKS - Apiserver NodeRestriction"의 두 판 사이의 차이

 
2번째 줄: 2번째 줄:
;[[Killer Shell CKS]] - Apiserver NodeRestriction
;[[Killer Shell CKS]] - Apiserver NodeRestriction
* https://killercoda.com/killer-shell-cks/scenario/apiserver-node-restriction
* https://killercoda.com/killer-shell-cks/scenario/apiserver-node-restriction
* 목적: node01의 Kubelet 신분으로, 금지 접두어(node-restriction.kubernetes.io/*)를 갖는 Node 레이블을 설정할 수 있는지 시험하여 NodeRestriction 어드미션 플러그인이 비활성화되어 있음을 확인
* kubelet이 자신의 Node 객체에 특정 접두어(node-restriction.kubernetes.io/*)레이블을 세팅하지 못하도록 Admission Plugin(NodeRestriction)을 활성화하고, 전후 동작을 검증하는 실습
 
----
* NodeRestriction 어드미션 플러그인이 활성화되어 있으면, Kubelet(주체: system:node:<노드명>, 그룹: system:nodes)은 자신(Node, 자신이 생성한 Pod) 범위를 벗어난 변경이나 특정 예약 접두어 레이블(node-restriction.kubernetes.io/*) 변경이 거부된다.
* 본 단계의 목표는 “현재는 제한이 적용되지 않음”을 증명하는 것이다. 따라서 node01의 kubelet 신분으로 위 접두어 레이블을 추가해 보고 성공한다면, 제한이 꺼져 있음을 확인할 수 있다.


<syntaxhighlight lang='console'>
<syntaxhighlight lang='console'>
15번째 줄: 11번째 줄:
</syntaxhighlight>
</syntaxhighlight>


==확인==
==검증1: 현재 제한이 없는지 확인==
node01 호스트에서 Kubelet 자격증명으로 API 서버에 접근해, 제한 접두어 레이블 추가를 시도한다.
node01 호스트에서 Kubelet 자격증명으로 API 서버에 접근해, 제한 접두어 레이블 추가한다.
<syntaxhighlight lang='console'>
<syntaxhighlight lang='console'>
controlplane:~$ ssh node01
controlplane:~$ ssh node01
38번째 줄: 34번째 줄:
</syntaxhighlight>
</syntaxhighlight>
위와 같이 Kubelet 자격으로 제한 접두어 레이블이 성공적으로 추가되었다면, 현재 NodeRestriction이 적용되지 않았음을 확인한 것이다.
위와 같이 Kubelet 자격으로 제한 접두어 레이블이 성공적으로 추가되었다면, 현재 NodeRestriction이 적용되지 않았음을 확인한 것이다.
==설정: NodeRestriction Admission Controller 활성화==
controlplane에서 kube-apiserver 정적 파드 매니페스트를 수정한다.
* 백업 권장
<syntaxhighlight lang='console'>
node01:~$ exit
logout
Connection to node01 closed.
controlplane:~$ cp /etc/kubernetes/manifests/kube-apiserver.yaml ~/kube-apiserver.yaml.bak
controlplane:~$ vim /etc/kubernetes/manifests/kube-apiserver.yaml
</syntaxhighlight>
* 매니페스트 수정
** 이미 --enable-admission-plugins 플래그가 있으면 기존 값에 NodeRestriction을 콤마로 추가한다.
** 없으면 새로 추가한다.
** --authorization-mode=Node,RBAC 이 포함되어 있어야 한다(일반적으로 이미 설정됨).
<syntaxhighlight lang='yaml'>
spec:
  containers:
  - command:
    - kube-apiserver
    - --advertise-address=172.30.1.2
    - --allow-privileged=true
    - --authorization-mode=Node,RBAC
    - --client-ca-file=/etc/kubernetes/pki/ca.crt
    - --enable-admission-plugins=NodeRestriction ## 추가
    - --enable-bootstrap-token-auth=true
    - --etcd-cafile=/etc/kubernetes/pki/etcd/ca.crt
</syntaxhighlight>
* 저장하면 kubelet이 정적 파드가 재시작된다.
<syntaxhighlight lang='console'>
controlplane:~$ crictl ps | grep apiserver
9b8b29b28cdaf      c3994bc696102      2 seconds ago      Running            kube-apiserver            0                  07f0f0e33c162      kube-apiserver-controlplane              kube-system
</syntaxhighlight>
==검증2: 제한 동작 확인==
* 다시 node01에서 kubelet 자격으로 제한 접두어 레이블을 추가 시도하면 거부되어야 한다.
<syntaxhighlight lang='console'>
controlplane:~$ ssh node01
Last login: Wed Nov 19 10:42:03 2025 from 10.244.0.131
node01:~$ export KUBECONFIG=/etc/kubernetes/kubelet.conf
node01:~$ k label node node01 node-restriction.kubernetes.io/two=123
Error from server (Forbidden): nodes "node01" is forbidden: is not allowed to modify labels: node-restriction.kubernetes.io/two
</syntaxhighlight>
* 다른 노드 객체를 수정하려 해도 기본적으로 거부된다(노드 자격은 다른 노드 수정 불가).
<syntaxhighlight lang='console'>
node01:~$ k label node controlplane killercoda/two=123
Error from server (Forbidden): nodes "controlplane" is forbidden: User "system:node:node01" cannot get resource "nodes" in API group "" at the cluster scope: node 'node01' cannot read 'controlplane', only its own Node object
</syntaxhighlight>
* 제한 접두어가 아닌 임의 접두어는 허용된다(자신의 노드에 한해).
<syntaxhighlight lang='console'>
node01:~$ k label node node01 test/two=123
node/node01 labeled
</syntaxhighlight>
* 참고: NodeRestriction을 활성화해도 기존에 달려 있던 제한 접두어 레이블은 자동으로 제거되지 않는다(필요 시 관리자가 별도로 제거).


==같이 보기==
==같이 보기==

2025년 11월 19일 (수) 19:53 기준 최신판

1 개요[ | ]

Killer Shell CKS - Apiserver NodeRestriction
controlplane:~$ k get node
NAME           STATUS   ROLES           AGE   VERSION
controlplane   Ready    control-plane   39h   v1.34.1
node01         Ready    <none>          39h   v1.34.1

2 검증1: 현재 제한이 없는지 확인[ | ]

node01 호스트에서 Kubelet 자격증명으로 API 서버에 접근해, 제한 접두어 레이블 추가한다.

controlplane:~$ ssh node01
Last login: Mon Feb 10 22:06:42 2025 from 10.244.0.131

node01:~$ export KUBECONFIG=/etc/kubernetes/kubelet.conf
node01:~$ k get node
Error from server (Forbidden): nodes is forbidden: User "system:node:node01" cannot list resource "nodes" in API group "" at the cluster scope: node 'node01' cannot read all nodes, only its own Node object

레이블 추가 시도:

node01:~$ k label node node01 node-restriction.kubernetes.io/one=123
node/node01 labeled

레이블이 실제로 적용되었는지 확인:

node01:~$ k get node node01 --show-labels | tr ',' '\n' | grep node-restriction.kubernetes.io/one
node-restriction.kubernetes.io/one=123

위와 같이 Kubelet 자격으로 제한 접두어 레이블이 성공적으로 추가되었다면, 현재 NodeRestriction이 적용되지 않았음을 확인한 것이다.

3 설정: NodeRestriction Admission Controller 활성화[ | ]

controlplane에서 kube-apiserver 정적 파드 매니페스트를 수정한다.

  • 백업 권장
node01:~$ exit
logout
Connection to node01 closed.

controlplane:~$ cp /etc/kubernetes/manifests/kube-apiserver.yaml ~/kube-apiserver.yaml.bak
controlplane:~$ vim /etc/kubernetes/manifests/kube-apiserver.yaml
  • 매니페스트 수정
    • 이미 --enable-admission-plugins 플래그가 있으면 기존 값에 NodeRestriction을 콤마로 추가한다.
    • 없으면 새로 추가한다.
    • --authorization-mode=Node,RBAC 이 포함되어 있어야 한다(일반적으로 이미 설정됨).
spec:
  containers:
  - command:
    - kube-apiserver
    - --advertise-address=172.30.1.2
    - --allow-privileged=true
    - --authorization-mode=Node,RBAC
    - --client-ca-file=/etc/kubernetes/pki/ca.crt
    - --enable-admission-plugins=NodeRestriction ## 추가
    - --enable-bootstrap-token-auth=true
    - --etcd-cafile=/etc/kubernetes/pki/etcd/ca.crt
  • 저장하면 kubelet이 정적 파드가 재시작된다.
controlplane:~$ crictl ps | grep apiserver
9b8b29b28cdaf       c3994bc696102       2 seconds ago       Running             kube-apiserver            0                   07f0f0e33c162       kube-apiserver-controlplane               kube-system

4 검증2: 제한 동작 확인[ | ]

  • 다시 node01에서 kubelet 자격으로 제한 접두어 레이블을 추가 시도하면 거부되어야 한다.
controlplane:~$ ssh node01
Last login: Wed Nov 19 10:42:03 2025 from 10.244.0.131

node01:~$ export KUBECONFIG=/etc/kubernetes/kubelet.conf
node01:~$ k label node node01 node-restriction.kubernetes.io/two=123
Error from server (Forbidden): nodes "node01" is forbidden: is not allowed to modify labels: node-restriction.kubernetes.io/two
  • 다른 노드 객체를 수정하려 해도 기본적으로 거부된다(노드 자격은 다른 노드 수정 불가).
node01:~$ k label node controlplane killercoda/two=123
Error from server (Forbidden): nodes "controlplane" is forbidden: User "system:node:node01" cannot get resource "nodes" in API group "" at the cluster scope: node 'node01' cannot read 'controlplane', only its own Node object
  • 제한 접두어가 아닌 임의 접두어는 허용된다(자신의 노드에 한해).
node01:~$ k label node node01 test/two=123
node/node01 labeled
  • 참고: NodeRestriction을 활성화해도 기존에 달려 있던 제한 접두어 레이블은 자동으로 제거되지 않는다(필요 시 관리자가 별도로 제거).

5 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}