- 파드 생성(명령어)
- 파드 이름 mypod1 mypod2
- 컨테이너 이름 mycon1 mycon2
- 이미지 nginx
- NS myns1
- Port 80
kubectl run mypod --image --port 80 -n myns1
kubectl run mypod --image=nginx \\
--overrides='
{
"apiVersion": "v1",
"kind": "Pod",
"spec": {
"containers": [{
"name": "mycon1",
"image": "nginx"
}]
}
}' \\
--dry-run=client -o yaml | kubectl apply -f -
kubectl describe pods mypod1
pod name
container name 확인 가능
- 파드 생성(YAML)
- 파드 이름 mypod3 mypod4
- 컨테이너 이름 mycon3 mycon4
- 이미지 nginx
- NS myns2
- Port 80
apiVersion: v1
kind: Pod
metadata:
name: mypod
namespace: myns1
spec:
containers:
- name: mycon1
image: nginx
ports:
- containerPort: 80
- name: mycon2
image: nginx
ports:
- containerPort: 81
- name: mycon3
image: nginx
ports:
- containerPort: 82
nginx는 기본적으로 80 포트만 오픈
81, 82를 사용하려면
nginx 설정 변경이 필요
apiVersion: v1
kind: ***Namespace***
metadata:
name: myns2
---
apiVersion: v1
kind: ***Pod***
metadata:
name: mypod3
***namespace : myns2***
spec:
containers:
- image: nginx
name: mycon
ports:
- containerPort: 80
protocol: TCP
---
apiVersion: v1
kind: ***Pod***
metadata:
name: mypod4
***namespace : myns2***
spec:
containers:
- image: nginx
name: mycon
ports:
- containerPort: 80
protocol: TCP
정상 작동
apiVersion: v1
kind: Namespace
metadata:
name: myns1
---
apiVersion: v1
kind: Pod
metadata:
name: mypod4
namespace: myns1
spec:
containers:
- name: mycon4
image: nginx
command: ["nginx", "-g", "daemon off;"]
ports:
- containerPort: 80
protocol: TCP
---
apiVersion: v1
kind: Pod
metadata:
name: mypod5
namespace: myns1
spec:
containers:
- name: mycon5
image: nginx
command: ["nginx", "-g", "daemon off;"]
ports:
- containerPort: 80
protocol: TCP
파드 > 컨테이너 구현 위한 쿠버네티스 최소 단위
하나 이상의 컨테이너 구현
[명령어 / YAML 파일]
apiversion: v1
kind: Pod
metadata:
name: mu
spec:
containers:
- image: nginx
name: myweb
ports:
- containerPort: 80
protocol: TCP
- name: ubun
image: ubuntu
command:
- sleep
- "86410"
curl http://
kubectl exec mu -it -c ubun -- bash
✅ 1. 방법 요약: Dockerfile + 커스텀 Nginx 설정 사용
① 커스텀 설정 파일 만들기 (custom.conf)
server {
listen 81;
location / {
root /usr/share/nginx/html;
index index.html;
}
}
server {
listen 82;
location / {
root /usr/share/nginx/html;
index index.html;
}
}
② Dockerfile 작성
FROM nginx
COPY custom.conf /etc/nginx/conf.d/default.conf
③ Docker 이미지 빌드
docker build -t nginx-custom .
④ Kubernetes YAML에 적용 (예시 - mycon2)
- name: mycon2
image: nginx-custom
ports:
- containerPort: 81
✅ 2. 또는 ConfigMap 사용하는 방법 (K8s 권장 방식)
① custom.conf 생성
동일한 listen 설정 사용.
② ConfigMap으로 생성
kubectl create configmap nginx-conf-81 --from-file=custom.conf
③ Pod에 마운트
- name: mycon2
image: nginx
volumeMounts:
- name: nginx-conf
mountPath: /etc/nginx/conf.d
volumes:
- name: nginx-conf
configMap:
name: nginx-conf-81
이렇게 하면 nginx 컨테이너가 포트 81이나 82에서 정상 동작
'IT 엔지니어 > CLOUD' 카테고리의 다른 글
| 초기화/인프라 컨테이너 (0) | 2025.05.25 |
|---|---|
| K8S - Load Balance (0) | 2025.05.24 |
| K8S POD 생성 (0) | 2025.05.22 |
| DOCKER NAMESPACE/STATEFULSET (0) | 2025.05.22 |
| Docker POD (1) | 2025.05.21 |