Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Info
iconfalse

 https://dev-k8sref-io.web.app/docs/workloads/replicaset-v1/

Info
iconfalse
  • apiVersion: apps/v1    #쿠버네티스 API버전을 가리킴

  • kind:  ReplicaSet. #리소스 유형

  • metadata (ObjectMeta): 포드와 관련된 이름, 네임스페이스, 라벨, 그밖의 정보

    • namespace
    • name
    • labels
  • spec (ReplicaSetSpec): PodTemplate

    • template         # Pods 명세

      • metadata
        • name
        • labels
      • spec
        • containers
        • volumes
    • selector     #labeling된 Pod선택

    • replicas      #복제본 수
  • status(ReplicaSetStatus) : 포드의 상태, 각 컨테이너의 설명 및 상태, 포드 내부의 IP 및 그밖의 기본 정보 등
  • Labels and Selectors

    • Pod Discovery 기능: Label이 "type: front-end" 인 Pod만 Select

Code Block
titlenginx-rs.yaml
linenumberstrue
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: nginx-rs
  labels:
    app: myapp-rs
    type: front-end
spec:
  template:
    metadata:
      name: nginx
      labels:
        app: myapp
        type: front-end
    spec:
      containers:
        - name: nginx
          image: nginx:1.14.2
          ports:
            - containerPort: 80
  selector:
    matchLabels:
      type: front-end
  replicas: 3
Info
iconfalse
Code Block
  selector:
    matchLabels:
      type: front-end
  • replicas

    • 유지할 Pod갯수
Code Block
   replicas: 3 


ReplicaSet 실습

Info
iconfalse
Code Block
sansae@sansaeAir15m2 ~ % k apply -f nginx-rs.yaml
replicaset.apps/nginx-rs created
Code Block
sansae@sansaeAir15m2 ~ % k get all
NAME                 READY   STATUS    RESTARTS   AGE
pod/nginx-rs-6dzx9   1/1     Running   0          91s
pod/nginx-rs-kbkn8   1/1     Running   0          91s
pod/nginx-rs-ml42r   1/1     Running   0          91s

NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP   10.0.0.1     <none>        443/TCP   6h13m

NAME                       DESIRED   CURRENT   READY   AGE

Scale

Code Block
$k replace -f nginx-rs.yaml
$k scale --replicas=6 -f nginx-rs.yaml
$k scale --replicas=6 rs nginx-rs

sansae@sansaeAir15m2 ~ % k scale --replicas=6 rs nginx-rs 
replicaset.apps/nginx-rs scaled
sansae@sansaeAir15m2 ~ % k get pod
NAME             READY   STATUS    RESTARTS   AGE
nginx-rs-6dzx9   1/1     Running   0          15m
nginx-rs-7mrz2   1/1     Running   0          9s
nginx-rs-hm85w   1/1     Running   0          9s
nginx-rs-kbkn8   1/1     Running   0          15m
nginx-rs-ml42r   1/1     Running   0          15m
nginx-rs-shljn   1/1     Running   0          9s

자가치유

Code Block
sansae@sansaeAir15m2 ~ % k get pod
NAME             READY   STATUS    RESTARTS   AGE
nginx-rs-4ksww   1/1     Running   0          10s
nginx-rs-5995j   1/1     Running   0          10s
nginx-rs-7lhv5   1/1     Running   0          10s
nginx-rs-8j45p   1/1     Running   0          10s
nginx-rs-lvh56   1/1     Running   0          10s
nginx-rs-wrhnv   1/1     Running   0          10s

sansae@sansaeAir15m2 ~ % k delete pod nginx-rs-wrhnv
pod "nginx-rs-wrhnv" deleted

sansae@sansaeAir15m2 ~ % k get pod
NAME             READY   STATUS    RESTARTS   AGE
nginx-rs-4ksww   1/1     Running   0          31s
nginx-rs-5995j   1/1     Running   0          31s
nginx-rs-6q445   1/1     Running   0          5s
nginx-rs-7lhv5   1/1     Running   0          31s
nginx-rs-8j45p   1/1     Running   0          31s
nginx-rs-lvh56   1/1     Running   0          31s

컨테이너 이미지 버전이 변경되었다면?

Info
iconfalse
Code Block
$k edit rs nginx-rs
-> image: nginx:1.14.2 --> nginx:15.12


replicaset.apps/nginx-rs edited
  • 명세는 수정되지만 실제 Pod가 변경되지는 않습니다.
    이미지 버전을 변경하기 위해서는 삭제 후 재생성해야 합니다.
    k delete -f nginx-rs.yaml
    k apply -f nginx-rs.yaml


...