모든 강의 이미지 출처는 [인프런] 쿠버네티스 어나더 클래스(지상편) - Spring 1,2 입니다.
nodeAffinity
설정이 필수적이다.apiVersion: v1
kind: PersistentVolume
metadata:
name: example-pv
spec:
capacity:
storage: 100Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Delete
storageClassName: local-storage
local:
path: /mnt/disks/ssd1 # 저장소로 사용할 Node의 로컬 경로 지정
nodeAffinity: # PV가 위치한 노드를 지정하는 Node Affinity (Pod에도 동일한 조건 지정 필요)
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- example-node
▶ Pod와 Node에 각각 file 생성 및 확인
# 파일 생성
[root@k8s-master ~] curl http://192.168.56.30:31231/create-file-pod
[root@k8s-master ~] curl http://192.168.56.30:31231/create-file-pv
▶ Pod 삭제 후 file 재확인
# Pod 삭제 후 파일 조회
[root@k8s-master ~] curl http://192.168.56.30:31231/list-file-pod
[root@k8s-master ~] curl http://192.168.56.30:31231/list-file-pv
▶ Deployment 설정에 PVC 대신 hostPath 사용하도록 변경 후 동작 확인
spec:
volumes:
- name: files
hostPath:
path: /root/k8s-local-volume/1231
▶ 결과
template
에 선언된 상태의 Pod를 replicas
수 만큼 생성한다.replicas
: ReplicaSet에서 생성할 Pod의 개수template
: ReplicaSet에서 생성할 Pod의 선언적 상태strategy
: 신규 Pod로 업데이트 시 사용할 배포 전략 (Recreate, RollingUpdate)apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
strategy:
type: RollingUpdate
maxUnavailable
, maxSurge
설정값에 따라 달라질 수 있다.maxUnavailable
: 배포 과정 중 사용할 수 없는 최대 파드의 수 또는 비율 (기본값 : 25%)maxSurge
: 배포 과정 중 생성할 수 있는 최대 파드의 수 또는 비율 (기본값 : 25%)maxUnavailable: 25%, maxSurge: 25%
▶ Deployment 설정
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 25%
maxSurge: 25%
▶ 결과
maxUnavailable: 0%, maxSurge: 100%
▶ Deployment 설정
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 0%
maxSurge: 100%
strategy:
type: Recreate
▶ 결과
▶ Deployment 설정
strategy:
type: Recreate
▶ 결과
▶ 이전 revision으로 롤백
[root@k8s-master ~] kubectl rollout undo -n anotherclass-123 deployment/api-tester-1231
▶ 결과 (이전 이미지 버전으로 롤백)
selector
: Service가 관리할 Pod들을 지정하기 위한 Label Selectortype
: Service의 유형 (ClusterIP, NodePort, LoadBalancer)ports
protocol
: Pod와 통신하기 위한 프로토콜 종류 (TCP 외 다른 프로토콜도 지원)targetPort
: Pod와 통신하기 위한 Port 번호port
: Service에 접근하기 위한 Port 번호nodePort
: NodePort 타입인 Service에서 사용하는 필드로, 각 Node에서 오픈하는 Port 번호▶ Pod 내부에서 Servie 명으로 API 호출
[root@k8s-master ~] kubectl exec -it api-tester-1231-6f4c85fb95-4c4nd -n anotherclass-123 -- curl http://api-tester-1231:80/version
▶ 결과
▶ Deployment, Service 설정 변경 후 Pod 내부에서 Servie 명으로 API 호출
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: anotherclass-123
name: api-tester-1231
spec:
template:
spec:
nodeSelector:
kubernetes.io/hostname: k8s-master
containers:
- name: api-tester-1231
ports: // 삭제
- name: http // 삭제
containerPort: 8080 // 삭제
---
apiVersion: v1
kind: Service
metadata:
namespace: anotherclass-123
name: api-tester-1231
spec:
ports:
- port: 80
targetPort: http -> 8080 // 변경
nodePort: 31231
type: NodePort
▶ 결과
변경될 Pod 수 = 현재 Pod 수 * (평균 CPU/HPA CPU)
변경될 Pod 수 = 2 * ((150+1)/2/60) = 3 (2.51 **올림 처리**)