[CKA] 컨테이너 Command와 Arguments
컨테이너 Command와 Arguments의 핵심 개념과 구성 방법, 실습 풀이를 정리합니다.
ENTRYPOINT 의 경우는 컨테이너가 시작시 실행하는 명령이며 CMD 는 명령에 전달되는 기본 매개 변수입니다.
apiVersion: v1
kind: Pod
metadata:
name: ubuntu-sleeper-pod
spec:
containers:
- name: ubuntu-sleeper
image: ubuntu-sleeper
args: ["10"]
파드 생성 에러
The Pod "ubuntu-sleeper-3" is invalid: spec: Forbidden: pod updates may not change fields other than `spec.containers[*].image`,`spec.initContainers[*].image`,`spec.activeDeadlineSeconds`,`spec.tolerations` (only additions to existing tolerations),`spec.terminationGracePeriodSeconds` (allow it to be set to 1 if it was previously negative)
기존에 이미 생성된 Pod를 수정하려고 시도했을 때 발생하는 것입니다. Kubernetes에서는 이미 생성된 Pod의 대부분의 필드를 수정할 수 없습니다.
spec.containers[*].imagespec.initContainers[*].imagespec.activeDeadlineSecondsspec.tolerations(기존 tolerations에 추가만 가능)spec.terminationGracePeriodSeconds(이전에 음수였던 경우 1로 설정 가능)
삭제했다가 재생성하는게 가장 간단한지만 시험에서 할 수 있는 접근 방법 중 간단하게 kubectl replace --force -f <tmp…> 구성하는 것 또한 가능합니다.
Dockerfile의 ENTRYPOINT를 유지하고 색상만 바꾸려면 Pod의 args를 사용합니다.
apiVersion: v1
kind: Pod
metadata:
name: webapp-green
labels:
name: webapp-green
spec:
containers:
- name: simple-webapp
image: example/webapp-color
args: ["--color", "green"]
FROM python:3.6-alpine
RUN pip install flask
COPY . /opt/
EXPOSE 8080
WORKDIR /opt
ENTRYPOINT ["python", "app.py"]
CMD ["--color", "red"]
kubectl CLI 옵션을 통해 매개변수 전달
kubectl run nginx --image=nginx -- nginx --arg1 arg2 ... argN