LimitRange 적용 테스트
이 단계에서는 LimitRange 에 정의된 리소스 제한을 초과하는 파드를 생성하여 LimitRange 의 적용을 테스트합니다. 방법은 다음과 같습니다.
pod-exceeding-limits.yaml이라는 새 YAML 파일을 다음 내용으로 생성합니다.
cd ~/project
touch pod-exceeding-limits.yaml
apiVersion: v1
kind: Pod
metadata:
name: example-pod-exceeding-limits
spec:
containers:
- name: nginx
image: nginx
resources:
limits:
cpu: "2"
memory: "2Gi"
이 파드 정의는 LimitRange 에 설정된 제한을 초과하는 리소스를 요청하는 컨테이너가 있는 파드를 생성합니다 (CPU: 2 코어, 메모리: 2 GiB).
kubectl apply 명령을 사용하여 pod-exceeding-limits.yaml 파일을 Kubernetes 클러스터에 적용합니다.
kubectl apply -f pod-exceeding-limits.yaml
파드 생성 작업이 거부되는 것을 확인할 수 있습니다. 오류 메시지는 Error from server (Forbidden): error when creating "pod-exceeding-limits. yaml": pod "example-pod-exceeding-limits " Forbidden: [Maximum cpu usage per container is 1, but limited to 2, maximum memory usage per container is 1Gi, but limited to 2Gi] 입니다.