• Home
  • About
    • Seokmin.Lee photo

      Seokmin.Lee

      Hello, I am a master's student in the Department of Convergence Security (Samsung Advanced Security) at Korea University.After graduation, I am expected as a security developer or researcher member of Samsung SDS.

    • Learn More
    • LinkedIn
    • Github
  • Posts
    • All Tags

[kubernetes]yaml다루기

13 Jun 2021

스크린샷 2021-06-13 오후 3 32 59

  • 기본 단위가 container가 아니라 pod임 ( 물론 container에 접근 할 수 있음)
  • container < pod < rs < deployment

1

kubectl create deployment --image=

kubectl get po/rs/deploy

2 yaml file을 사용해서 구성한다.

kubectl apply -f

  • 기본적으로 key-value 파일이다.

kubectl get deploy –watch 켜놓고 보는 것이 편함 스크린샷 2021-06-13 오후 3 46 17 스크린샷 2021-06-13 오후 5 01 20

내가 생성하고 싶은 rs의 갯수들을 편하게 설정할 수 있음

yaml파일 세부 분석

apiVersion: apps/v1
kind: Deployment //deplyment를 위한 yaml파일이다.
metadata:        //deployment의 세부정보
  name: nginx-deployment //deployment의 이름
  labels:
    app: nginx  //세부적으로 할당 될 nginx이름
spec:
  replicas: 3 //replicas의 갯수
  selector:
    matchLabels: //해당되는 pod의 이름은!?
      app: nginx //nginx
  template:
    metadata:
      labels:
        app: nginx //pod
    spec:
      containers:
      - name: nginx //세부적인 container는 다음과 같다.
        image: nginx:1.14.2
        ports:
        - containerPort: 80 

expose를 yaml파일로 만들어보기!

apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  tyep: LoadBalancer
  selector:
    app: nginx
  ports:
  - protocal: TCP
    port: 8040
    targetPort: 80
  • 이서비스가 deployment의 spec위의 nginx의 label의 값과 selector의 app의 nginx의 값에 대해서 동일하게 적어줘야함

    kubectl get all (로 전체 image 확인) 스크린샷 2021-06-13 오후 4 11 12

minicube service list (로 ip 확인가능) 스크린샷 2021-06-13 오후 4 11 43

  • 8040 port로 안나오는 이유는 자체적으로 32340로 pending 되었기 떄문이다. 스크린샷 2021-06-13 오후 4 12 39

이제 이 index를 바꿔보는 실습하기

  1. kubectl get po로 해당 pod 찾기 (난왜 3개지..?) –> nginx.yaml에서 3개로 설정했기에! 1개로 바꿔서 시간단축하기! 스크린샷 2021-06-13 오후 4 16 01

  2. 해당 pod를 bash로 열기 스크린샷 2021-06-13 오후 4 17 14

  3. cd /usr/share/nginx/html/index.html 으로 이동해주고 수정하기 스크린샷 2021-06-13 오후 4 18 58

  4. cat 또는 echo로 수정해주기

스크린샷 2021-06-13 오후 4 23 16

  1. 3개의 pod가 생성이 되었다면 가장 첫번째 파드가 외부와 연결되어 있는 pod이다.

삭제

yaml파일 자체를 지워버림

kuberctl delete -f ___.yaml

스크린샷 2021-06-13 오후 5 02 59

kuberctl delete deploy nginx-name

kuberctl delete src service-name

스크린샷 2021-06-13 오후 4 48 56

최종 복습 yaml 실습

1. nginx label 변경

스크린샷 2021-06-13 오후 4 51 35

2. nginx service.yaml 변경

스크린샷 2021-06-13 오후 4 50 46

3. mimikube service list로 확인 및 url 접근

스크린샷 2021-06-13 오후 4 52 44 스크린샷 2021-06-13 오후 4 53 17

4. pod확인 및 bash로 들어가기

스크린샷 2021-06-13 오후 4 54 30

cd /usr/share/nginx/html/index.html 수정

스크린샷 2021-06-13 오후 4 57 01

안되면 많은 pod들 중에 하나 선택해서 그냥 해보면 됨, 그냥 순차적으로 하는 것을 추천

deploy & service 파일을 하나로 합칠 수 있음

— 쓰고 사용 스크린샷 2021-06-13 오후 5 07 40

성공적

스크린샷 2021-06-13 오후 5 09 20



cloudkubernetes Share Tweet +1