[kubernets] Pod / ReplicaSet 생성

‍정진철·2023년 5월 22일
0

Kubernetes

목록 보기
2/4

Pod 생성 하기 위한 yaml 파일 생성

simple-pod.yml

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: {}
  • metadata 는 key:value 형태로서 지정을 해주는 것으로서 해당 Pod에 대한 이름 즉, 라벨링을 해주는 작업이다.
  • spec 속성에 내가 팟안에 넣어줄 컨테이너에 대한 정보들을 명시한다.
  • 이곳에서는 크게 nginx, redis 로 구성한다.

! 잠깐 그전에 .. !

기존에 존재하는 service 와 deployment가 보이니 해당 pod/service 정보를 삭제하자.

kubectl delete deployment <pod이름>
kubectl delete service <서비스명>


Pod 생성 ( with yaml_file)

kubectl apply -f simple-pod.yaml

특정 Pod에 Access 하기

nginx 서버에 접근

kubectl exec --stdin --tty my-little-pod -c nginx --sh

redis-server에 접근

kubectl exec --stdin --tty my-little-pod -c redis --redis-server --version


Pod 삭제


replicaSet 생성하기

위에서 생성한 my-little-pod 을 동일하게 3개 복제
이름은 my-replicaset 이며 label 명 역시 동일

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: {}

kubectl apply -f simple-replicaset.yaml

kubectl get rs
Get the current ReplicaSets deployed

kubectl describe rs/my-replicaset
Check on the state of the ReplicaSet


kubectl get pods

kubectl get pods my-replicaset-45wkc -o yaml
Get the yaml of a Pod

kubectl exec --stdin --tty my-replicaset-45wkc -c nginx -- sh
특정 replica container에 접속

kubectl exec --stdin --tty my-replicaset-45wkc -c redis -- redis-server --version

kubectl get pod,replicaset,deployment --selector app=my-little-pod
kubectl get pod,replicaset,deployment --selector app=my-replicaset

특정 pod, replicaSet 확인.


replicaSet 삭제

profile
WILL is ALL

0개의 댓글