1. Controller
1.1 Auto Healing
종류:
1.2 Auto Scaling
종류:
1.3 Software Update
종류:
1.4 Job
종류:
2. Replication Controller/ ReplicaSet
파드의 버전을 업데이트 하는 방법
Replication Controller의 경우 label 이 동일할 경우만 연결이 된다.
2.4. ReplicationController에서 ReplicaSet으로 변경방법
아래 명령어로 연결된 pod는 지우지 않고 ReplicationController만 삭제
$ kubectl delete replicationcontrollers replication1 --cascade=falseReplicaSet 생성
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: replica2
spec:
replicas: 2
selector:
matchLabels:
cascade: "false"
template:
metadata:
labels:
cascade: "false"
spec: #아래 스펙내용은 기존 ReplicationController 와 동일하게
containers:
- name: container
image: kubetm/app:v12.5. ReplicaSet 샘플
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: replica1
spec:
replicas: 2 #파드개수를 replicas 만큼 유지를 시킨다.
selector:
matchLabels:
type: web #동일한 라벨링 된 파드와 연결이 된다.
ver: v1 #만약 template 아래 labels에 존재하지 않는 라벨을 사용할 경우 에러 발생(ex. ver: v3)
template:
metadata:
name: pod1 #ReplicaSet이 해당 템플릿으로 Pod를 생성하면 "pod1"로 파드명이 만들어지지 않고 임의의 파드명으로 생성된다.
labels:
type: web
ver: v1
ver: v2
spec:
containers:
- name: container
image: kubetm/app:v1
terminationGracePeriodSeconds: 0apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: replica1
spec:
replicas: 1
selector:
#matchLabels, matchExpressions 두 조건 모두 들어갈 수 있다. or 조건이다. (matchLabels or matchExpressions)
#template 아래 labels에 존재하는 라벨만 사용가능
matchLabels:
type: web
ver: v1
matchExpressions:
- {key: type, operator: In, values: [web]}
- {key: ver, operator: Exists}
template:
metadata:
labels:
type: web
ver: v1
location: dev
spec:
containers:
- name: container
image: kubetm/app:v1
terminationGracePeriodSeconds: 0Recreate Deployment 리소스파일
apiVersion: apps/v1
kind: Deployment
metadata:
name: deployment-1
spec:
selector:
matchLabels:
type: app
replicas: 2
strategy:
type: Recreate #type 설정
revisionHistoryLimit: 1 #삭제하지 않고 유지 할 ReplicaSet 개수, 기본값은 10
template:
metadata:
labels:
type: app
spec:
containers:
- name: container
image: kubetm/app:v1
terminationGracePeriodSeconds: 10어떻게 새로 생성된 파드들은 새로 생성된 ReplicaSet을 구별하나?
RollingUpdate Deployment 리소스파일
apiVersion: apps/v1
kind: Deployment
metadata:
name: deployment-2
spec:
selector:
matchLabels:
type: app2
replicas: 2
strategy:
type: RollingUpdate #type 설정
minReadySeconds: 10
template:
metadata:
labels:
type: app2
spec:
containers:
- name: container
image: kubetm/app:v1
terminationGracePeriodSeconds: 0어떻게 새로 생성된 파드들은 새로 생성된 ReplicaSet을 구별하나?
Blue/Green ReplicaSet 리소스파일
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: replica1 # -> replica2로 변경하여 배포 (새로운 ReplicaSet 생성됨)
spec:
replicas: 2
selector:
matchLabels:
ver: v1 # -> v2로 변경하여 배포
template:
metadata:
name: pod1
labels:
ver: v1 # -> v2로 변경하여 배포
spec:
containers:
- name: container
image: kubetm/app:v1 # -> 업데이트할 이미지로 변경하여 배포
terminationGracePeriodSeconds: 0Blue/Green Service 리소스파일
apiVersion: v1
kind: Service
metadata:
name: svc-3
spec:
selector:
ver: v1 # -> v2로 변경하여 배포 (새로운 파드로 연결)
ports:
- port: 8080
protocol: TCP
targetPort: 8080불특정 다수 테스트
특정 타겟 테스트
hostPort를 사용하면 (service의 노드포트 설정) + (externalTrafficPolicy: Local) 옵션을 준 것과 동일하다.
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: daemonset-2
spec:
selector:
matchLabels:
type: app
template:
metadata:
labels:
type: app
spec:
nodeSelector: #node를 선택할 수 있다.
os: centos
containers:
- name: container
image: kubetm/app
ports:
- containerPort: 8080
hostPort: 18080 #hostPort 옵션 적₩5.1. Pod
5.2. ReplicaSet
Recreate vs Restart
- Recreate는 파드를 재생성하여 IP나 파드명이 변경이 된다.
- Restart는 파드를 재생성하지 않고 안의 컨테이너만 재시작한다.5.3. Job
apiVersion: batch/v1
kind: Job
metadata:
name: job-2
spec:
completions: 6
parallelism: 2
activeDeadlineSeconds: 30
template:
spec:
restartPolicy: Never
containers:
- name: container
image: kubetm/init
command: ["sh", "-c", "echo 'job start';sleep 20; echo 'job end'"]
terminationGracePeriodSeconds: 05. CronJob
#v1.22
apiVersion: batch/v1
kind: CronJob
metadata:
name: cron-job
spec:
schedule: "*/1 * * * *"
jobTemplate:
spec:
template:
spec:
restartPolicy: Never
containers:
- name: container
image: kubetm/init
command: ["sh", "-c", "echo 'job start';sleep 20; echo 'job end'"]
terminationGracePeriodSeconds: 0
---
#v1.15
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: cron-job-2
spec:
schedule: "20,21,22 * * * *"
concurrencyPolicy: Replace
jobTemplate:
spec:
template:
spec:
restartPolicy: Never
containers:
- name: container
image: kubetm/init
command: ["sh", "-c", "echo 'job start';sleep 140; echo 'job end'"]
terminationGracePeriodSeconds: 0