개발강의정리/DevOps

[데브옵스를 위한 쿠버네티스 마스터] 4. 쿠버네티스 핵심 개념

nineDeveloper 2020. 8. 22.
728x90

1 포드 디스크립터 작성

go-http-pod.yaml

apiVersion: v1
kind: Pod
metadata:
  name: http-go
spec:
  containers:
  - name: http-go
    image: gasbugs/http-go
    ports:
    - containerPort: 8080

2 포드 연습문제 풀어보기

jenkins-manual-pod.yaml

apiVersion: v1
kind: Pod
metadata:
  name: jenkins-manual
spec:
  containers:
  - name: jenkins
    image: jenkins
    ports:
    - containerPort: 8080

3 라이브네스 레디네스 프로브 실습

exec-liveness.yaml

apiVersion: v1
kind: Pod
metadata:
  labels:
    test: liveness
  name: liveness-exec
spec:
  containers:
  - name: liveness
    image: k8s.gcr.io/busybox
    args:
    - /bin/sh
    - -c
    - touch /tmp/healthy; sleep 30; rm -rf /tmp/healthy; sleep 600
    livenessProbe:
      exec:
        command:
        - cat
        - /tmp/healthy
      initialDelaySeconds: 5
      periodSeconds: 5

http-liveness.yaml

apiVersion: v1
kind: Pod
metadata:
  labels:
    test: liveness
  name: liveness-http
spec:
  containers:
  - name: liveness
    image: k8s.gcr.io/liveness
    args:
    - /server
    livenessProbe:
      httpGet:
        path: /healthz
        port: 8080
        httpHeaders:
        - name: Custom-Header
          value: Awesome
      initialDelaySeconds: 3
      periodSeconds: 3

tcp-liveness-readiness.yaml

apiVersion: v1
kind: Pod
metadata:
  name: goproxy
  labels:
    app: goproxy
spec:
  containers:
  - name: goproxy
    image: k8s.gcr.io/goproxy:0.1
    ports:
    - containerPort: 8080
    readinessProbe:
      tcpSocket:
        port: 8080
      initialDelaySeconds: 5
      periodSeconds: 10
    livenessProbe:
      tcpSocket:
        port: 8080
      initialDelaySeconds: 15
      periodSeconds: 20

4 레이블 추가, 생성, 삭제, 필터링 실습

http-go-pod-v2.yaml


apiVersion: v1
kind: Pod
metadata:
  name: http-go
  labels:
    creation_method: manual
    env: prod
spec:
  containers:
  - name: http-go
    image: gasbugs/http-go
    ports:
    - containerPort: 8080
      protocol: TCP

http-go-pod-v3.yaml

apiVersion: v1
kind: Pod
metadata:
name: http-go-v3
labels:
creation_method: manual-v3
spec:
containers:

- name: http-go
image: gasbugs/http-go
ports:
    - containerPort: 8080
    protocol: TCP

5 레이블과 셀렉터 연습문제

nginx-pod.yaml

apiVersion: v1
kind: Pod
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  containers:
  - name: nginx
    image: nginx
    ports:
    - containerPort: 80
      protocol: TCP

6 레플리케이션 컨트롤러 실습

http-go-rc.yaml

apiVersion: v1
kind: ReplicationController
metadata:
  name: http-go
spec:
  replicas: 3
  selector:
    app: http-go
  template:
    metadata:
      name: http-go
      labels:
        app: http-go
    spec:
      containers:
      - name: http-go
        image: gasbugs/http-go
        ports:
        - containerPort: 8080

7 레플리카셋 개요와 연습문제

nginx-rs.yaml

apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: rs-nginx
spec:
  # modify replicas according to your case
  replicas: 3
  selector:
    matchLabels:
      app: rs-nginx
  template:
    metadata:
      labels:
        app: rs-nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        ports: 
        - containerPort: 80

8 디플로이먼트 소개와 연습문제

jenkins-deploy.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: deploy-jenkins
  labels:
    app: jenkins-test
spec:
  replicas: 3
  selector:
    matchLabels:
      app: jenkins-test
  template:
    metadata:
      labels:
        app: jenkins-test
    spec:
      containers:
      - name: jenkins
        image: jenkins
        ports:
        - containerPort: 8080

9 롤링 업데이트와 롤백 실습

http-go-deploy-v1.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: http-go
  labels:
    app: http-go
spec:
  replicas: 3
  selector:
    matchLabels:
      app: http-go
  template:
    metadata:
      labels:
        app: http-go
    spec:
      containers:
      - name: http-go
        image: gasbugs/http-go:v1
        ports:
        - containerPort: 8080

10 롤링 업데이트와 롤백 연습문제

alpine-deploy.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    run: alpine-deploy
  name: alpine-deploy
spec:
  replicas: 10
  selector:
    matchLabels:
      run: alpine-deploy
  strategy: 
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 50%
      maxUnavailable: 50%
  template:
    metadata:
      creationTimestamp: null
      labels:
        run: alpine-deploy
    spec:
      containers:
      - image: alpine:3.4
        name: alpine-deploy
        resources: {}
status: {}

11 네임스페이스 소개와 실습

office-ns.yaml

apiVersion: v1
kind: Namespace
metadata:
  creationTimestamp: null
  name: office
spec: {}
status: {}

12 네임스페이스 연습문제

jenkins-ns.yaml

apiVersion: v1
kind: Namespace
metadata:
  name: ns-jenkins
---
apiVersion: v1
kind: Pod
metadata:
  name: jenkins
  namespace: ns-jenkins
spec:
  containers:
  - name: jenkins
    image: jenkins
    ports:    
    - containerPort: 8080

13 Cluster IP와 SessionAffinity 실습

http-go-deploy.yaml

apiVersion: v1
kind: Service
metadata:
  name: http-go-svc
spec:
  selector:
    run: http-go
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080
---

apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    run: http-go
  name: http-go
spec:
  replicas: 1
  selector:
    matchLabels:
      run: http-go
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        run: http-go
    spec:
      containers:
      - image: gasbugs/http-go
        name: http-go
        ports:
        - containerPort: 8080
        resources: {}
status: {}

14 노드포트로 서비스하기 실습

http-go-np.yaml

apiVersion: v1
kind: Service
metadata:
  name: http-go-np
spec:
  type: NodePort
  selector:
    run: http-go
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080
      nodePort: 30001

15 로드밸런서로 서비스하기 실습

http-go-lb.yaml


apiVersion: v1
kind: Service
metadata:
  name: http-go-lb
spec:
  type: LoadBalancer
  selector:
    run: http-go
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080

16 노드포트, 로드밸런서 연습문제

tomcat-deploy-np-lb.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    run: tomcat
  name: tomcat
spec:
  replicas: 1
  selector:
    matchLabels:
      run: tomcat
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        run: tomcat
    spec:
      containers:
      - image: consol/tomcat-7.0
        name: tomcat
        ports:
        - containerPort: 8080
        resources: {}
status: {}
---
apiVersion: v1
kind: Service
metadata:
  name: tomcat-np
spec:
  type: NodePort
  selector:
    run: tomcat
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080
      nodePort: 30002
---
apiVersion: v1
kind: Service
metadata:
  name: tomcat-lb
spec:
  type: LoadBalancer
  selector:
    run: tomcat
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080

17 인그레스(ingress) 실습

http-go-ingress.yaml

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: http-go-ingress
spec:
  rules:
  - host: gasbugs.com
    http:
      paths:
      - path: /
        backend:
          serviceName: http-go-svc
          servicePort: 80

18 인그레스(ingress) 연습문제

GKE에서 인그레스를 활용한 로드밸런싱 프로세스 확인

19 서비스 DNS 연습문제

blue-jenkins-svc-deploy.yaml

apiVersion: v1
kind: Namespace
metadata:
  creationTimestamp: null
  name: blue
spec: {}
status: {}
---
apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    run: pod-jenkins
  name: pod-jenkins
  namespace: blue
spec:
  replicas: 1
  selector:
    matchLabels:
      run: pod-jenkins
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        run: pod-jenkins
    spec:
      containers:
      - image: jenkins
        name: pod-jenkins
        ports:
        - containerPort: 8080
        resources: {}
status: {}
---
apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  labels:
    run: pod-jenkins
  name: srv-jenkins
  namespace: blue
spec:
  ports:
  - port: 8080
    protocol: TCP
    targetPort: 8080
  selector:
    run: pod-jenkins
status:
  loadBalancer: {}

20 EmptyDir을 활용한 컨테이너 간 데이터 공유 실습

count-httpd.yaml

apiVersion: v1
kind: Pod
metadata:
  name: count
spec:
  containers:
  - image: gasbugs/count
    name: html-generator
    volumeMounts:
    - name: html
      mountPath: /var/htdocs
  - image: httpd
    name: web-server
    volumeMounts:
    - name: html
      mountPath: /usr/local/apache2/htdocs
      readOnly: true
    ports:
    - containerPort: 80
      protocol: TCP
  volumes:
  - name: html
    emptyDir: {}

21 hostpath 컨테이너와 노드 간 데이터 공유 실습

hostpath-httpd.yaml

apiVersion: v1
kind: Pod
metadata:
  name: hostpath-http
spec:
  containers:
  - image: httpd
    name: web-server
    volumeMounts:
    - name: html
      mountPath: /usr/local/apache2/htdocs
      readOnly: true
    ports:
    - containerPort: 80
      protocol: TCP
  volumes:
  - name: html
    hostPath:
       path: /var/htdocs
       type: Directory

22 GCE 디스크를 활용한 네트워크 볼륨 연결

gce-mongodb-pod.yaml

apiVersion: v1
kind: Pod
metadata:
  name: mongodb
spec:
  containers:
  - image: mongo
    name: mongodb
    volumeMounts:
    - mountPath: /data/db
      name: mongodb
  volumes:
  - name: mongodb
    gcePersistentDisk:
      pdName: mongodb
      fsType: ext4

23 k8s와 네트워크 볼륨 연결 실습

nfs-httpd.yaml

apiVersion: v1
kind: Pod
metadata:
  name: nfs-httpd
spec:
  containers:
  - image: httpd
    name: web
    volumeMounts:
    - mountPath: /usr/local/apache2/htdocs
      name: nfs-volume
      readOnly: true
  volumes:
  - name:  nfs-volume
    nfs:
      server: 10.0.2.5
      path: /home/nfs

24 애플리케이션 스케줄링과 라이프사이클 관리

mongo-pv-pvc-pod.yaml

apiVersion: v1
kind: Pod
metadata:
  name: mongodb
spec:
  containers:
  - image: mongo
    name: mongodb
    volumeMounts:
    - mountPath: /data/db
      name: mongodb
  volumes:
  - name: mongodb
    persistentVolumeClaim:
      claimName: mongo-pvc
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mongo-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
  storageClassName: ""
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: mongo-pv
spec:
  capacity:
    storage: 10Gi
  volumeMode: Filesystem
  accessModes:
  - ReadWriteOnce
  - ReadOnlyMany
  persistentVolumeReclaimPolicy: Retain
  gcePersistentDisk:
    pdName: mongodb
    fsType: ext4

25 GCE 동적 프로비저닝 실습

mongo-storage.yaml

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: storage
provisioner: kubernetes.io/gce-pd
parameters:
  type: pd-ssd
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mongo-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
  storageClassName: storage
---
apiVersion: v1
kind: Pod
metadata:
  name: mongodb
spec:
  containers:
  - image: mongo
    name: mongodb
    volumeMounts:
    - mountPath: /data/db
      name: mongodb
  volumes:
  - name: mongodb
    persistentVolumeClaim:
      claimName: mongo-pvc
728x90

댓글

💲 추천 글