
어플리케이션이 죽을때, 최소로 돌아가는 어플리케이션을 유지할 수 있도록 해준다.
Replicaset은 새로 나온 권장되는 기능이다.
이제는 replicaset이 보편적으로 사용되고, 더 이상 controller는 사용되지않는다.
그러나 여기에서는 둘다 다룬다.
//replica-definition.yml
apiVersion: v1
kind: ReplicationController
metadata:
name: myapp-rc // user-define
labels:
app: myapp
type: front-end
spec:
template:
//여기부터는 pod-definition.yml
metadata:
name: myapp-pod
labels:
app: myapp
type: front-end
spec:
containers:
- name: nginx-container
image: nginx
//여기까지
//몇개의 파드를 유지하고 싶은지 명시.
replicas: 3
kubectl get replicationcontroller
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: myapp-replicaset
labels:
app: myapp
type: front-end
spec:
template:
//여기부터 pod의 metadata 기재
metadata:
name: myapp-pod
labels:
app: myapp
type: front-end
spec:
containers:
- name: nginx-container
image: nginx
replicas: 3
selector:
matchLabels:
type: front-end
kubectl get replicaset
모니터링할 타켓 리소스을 구분할 수 있게해줌
kubectl replace -f replicaset-definition.yml(filename.yml)
#or
kubectl scale --replicas=6 -f filename.yml
#or
kubectl scale --replicas=6 replicaset(type) myapp-replicaset(name)
도커 인스턴스들을 중단없이 매끄럽게 업그레이드
Rolling Update: 새로운 버전의 애플리케이션 컨테이너를 하나씩 점진적으로 배포하면서, 동시에 구버전 컨테이너를 하나씩 제거하는 방식입니다. 이 덕분에 전체 서비스가 중단되는 순간이 없습니다.
#deployment-definition.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp-deployment
labels:
app: myapp
type: front-end
spec:
template:
metadata:
name: myapp-pod
labels:
app: myapp
type: front-end
spec:
containers:
- name: nginx-container
image: nginx
replicas: 3
selector: //옵셔널
matchLabels:
type: front-end
kubectl create -f deployment-definition.yml
kubectl get deployments
kubectl get replicaset
kubectl get pods
# etc
kubectl get all
deployment이라는 객체를 따로 생성.
—> 다른 차이점들을 다음 강의에 알려주시기로… 음..
| Deployments | ReplicaSet |
|---|---|
| rolling updates, rollbacks, versioning등 추가기능들을 지원하는 고수준의 추상화 기술 | 명시된 개수의 파드replicaset을 관리하는 저수준의 추상화 기술. |
| (기본 스케일링과 self-healing 지원) | |
| 파드 template을 관리함. | |
| replicaset을 이용해서, 특정 개수 파드 replica를 유지하도록 함. | 명시된 개수의 파드 replicas만 관리. |
| 자동 롤링 업데이트, 롤백을 통해서, | |
| 다운타임 최소화해준다 | 수동으로 업데이트 / 롤백 필요 |
| 버저닝 지원 → 롤백이 쉽다. | 버저닝 지원 x |
strategy라는 옵션이 있다.
이 옵션을 통해
recreate, 혹은 rolling update를 설정할수있고,
rolling update의 상세사항인, maxsurge등을 설정할수있다.
클러스터 생성시 자동생성되는 3가지 네임스페이스가있다.
같은 클러스터를 사용하고 싶지만, 리소스를 구분하고싶을때. namespace를 구분할수있다.
Q. 네임스페이스는 클러스터간에도 같은 네임스페이스를 넣을수있는건지.?
# automatically add DNS service name
mysql.connect("db-service.dev.svc.cluster.local")
# "servicename.namespace.service.domain(=cluster.local)"
# namespace를 지정하고싶을때. pod-definition.yml
apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
**namespace: dev # namespace를 지정할수있음**
labels:
app: myapp
type: front-end
spec:
containers:
- name: nginx-container
image: nginx
apiVersion: v1
kind: Namespace
metadata:
name: dev
kubectl create namespace dev
get pods를 통해 정보 조회 시, 원하는 namespace를 지정하지않으면 default namespace가 조회된다.
kubectl config set-context $(kubectl config current-context) --namespace=dev#모든 네임스페이스의 파드 조회
kubectl get pods --all-namespaces
네임스페이스의 쿼타를 yml를 통해 지정가능.
apiVersion: v1
kind: ResourceQuota
metadata:
name: compute-quota
namespace: dev
spec:
hard:
pods: "10"
requests.cpu: "4"
requests.memory: 5Gi
limits.cpu: "10"
limits.memory: 10Gi.