[Kubernetes] ReplicaSet Controller

2024. 5. 27. 18:45ComputerScience/DockerKubernetes

 

 

 

 

2024. 05. 27 Monday 

https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/

 

ReplicaSet

A ReplicaSet's purpose is to maintain a stable set of replica Pods running at any given time. Usually, you define a Deployment and let that Deployment manage ReplicaSets automatically.

kubernetes.io

 

 

 

 

 

# simple-pod.yaml

apiVersion: v1
kind: Pod
metadata:
  name: my-little-pod
spec:
  containers:
  - name: nginx
    image: nginx:latest
    ports:
    - containerPort: 80
  - name: redis
    image: redis
    volumeMounts:
    - name: redis-storage
      mountPath: /data/redis
  volumes:
  - name: redis-storage
    emptyDir: {}

 

 

 

 

 

# simple-replicaset.yaml

apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: my-replicaset
  labels:
    app: my-replicaset
spec:
  replicas: 3
  selector:
    matchLabels:
      app: my-little-pod
  template:
    metadata:
      labels:
        app: my-little-pod
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - containerPort: 80
      - name: redis
        image: redis
        volumeMounts:
        - name: redis-storage
          mountPath: /data/redis
      volumes:
      - name: redis-storage
        emptyDir: {}

 

 

 

 

 

minikube start

 

 

 

 

 

kubectal get all - 늘 기본으로 떠있는 ClusterIP

 

 

 

 

 

nginx 쉘을 실행한 모습! uname 물어보고 exit

 

 

 

 

 

redis 서버 버전 물어보기 (--version)

 

 

 

 

 

delete -f로 pod 지우기

 

 

 

 

 

apply -f replicaset 얌파일

 

 

 

 

 

kubectl get rs - replicaset을 가져온다

 

 

 

 

 

kubectl describe rs/my-replicaset 

레플리카셋에 대한 정보를 볼 수 있다 

 

 

 

 

 

kubectl get pods

 

 

 

 

 

kubectl get pods ~~ -o yaml 

pod의 얌파일을 보여줌 -> 내가 작성한 내용보다 더 많은 것들이 들어가있음 

 쿠버네티스가 하는 일이 되게 많구나!

 

 

 

 

 

pod 죽이기

 

 

 

 

 

죽은 팟에 대하여, 쿠버네티스가 새롭게 팟을 띄우는 모습!

(AGE를 통해 갓 태어난 pod을 확인할 수 있다)

3개를 유지하려고 노력하는 쿠버네티스의 모습 wow 

 

 

 

 

 

my-little-pod 라벨을 가져와라

* 라벨 써먹기 - 앞에서 라벨 건 애들 보는 것 

 

 

 

 

 

이번 라벨은 my-replicaset

 

 

 

 

 

replicaset delete

 

 

 

minikube stop을 마지막으로 

이번 컨트롤러 실습 마무리 :)