Name
Last commit
Last update
..
.gitkeep k8s, oper update1
README.md k8s, oper update4

logo

MON Operation Overview

K8s 기반의 Nginx Front-End System Overview

K8s Deployment Current Status

# kubectl get pods -o wide |grep monitor-nginx
monitor-nginx-7cdb67c44f-c7x47           1/1     Running   0          5d23h   10.244.3.252   tb3          <none>           <none>
monitor-nginx-7cdb67c44f-fb8tk           1/1     Running   0          5d23h   10.244.6.142   tb2          <none>           <none>

Nginx Deployment yaml

역할 : Nginx POD를 배포하는 Deployment를 작성한다.

# cat mon_nginx.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginx
  name: monitor-nginx
spec:
  replicas: 2
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: servertype
                operator: NotIn
                values:
                - master
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: app
                operator: In
                values:
                - nginx
            topologyKey: "kubernetes.io/hostname"
      volumes:
      - name: mon-home-volume
        persistentVolumeClaim:
          claimName: mon-home-volume-pvc
      dnsPolicy: "None"
      dnsConfig:
        nameservers:
         - 8.8.8.8
         - 61.100.0.136
         - 61.100.0.152
      containers:
      - image: harbor.hongsnet.net/monitor/monitoring-nginx:20220801_32
        imagePullPolicy: IfNotPresent
        name: monitor-nginx
        volumeMounts:
         - mountPath: /home
           name: mon-home-volume
      imagePullSecrets:
        - name: harbor-login

Nginx HPA Scale yaml

역할 : AutoScaling 정책을 작성한다.

# cat mon_scale_nginx.yaml
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
  name: nginx-hpa
  namespace: default
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: monitor-nginx
  minReplicas: 2
  maxReplicas: 3
  targetCPUUtilizationPercentage: 80

Nginx Service yaml

역할 : Nginx Service를 작성한다. 여기서는 NodePort 방식을 통해 배포한다.

# cat mon_service_nginx.yaml
apiVersion: v1
kind: Service
metadata:
  name: monitor-nginx
spec:
  externalTrafficPolicy: Local
  type: NodePort
  selector:
    app: nginx
  ports:
    - name: nginx
      port: 80
      protocol: TCP
      targetPort: 80
      nodePort: 32000

실행

배포 및 관리는 여러 가지 방법이 있지만, 여기서는 kubectl 을 사용하여 실행한다.

  • 시작 스크립트
# cat start-mon_nginx.sh
#!/bin/bash

kubectl create -f mon_nginx.yaml
kubectl create -f mon_scale_nginx.yaml
kubectl create -f mon_service_nginx.yaml

실행결과는 다음과 같다.

# ./start-mon_nginx.sh
deployment.apps/monitor-nginx created
horizontalpodautoscaler.autoscaling/nginx-hpa created
service/monitor-nginx created
  • 중지 스크립트
# cat stop-mon_nginx.sh
#!/bin/bash

kubectl delete -f mon_service_nginx.yaml
kubectl delete -f mon_scale_nginx.yaml
kubectl delete -f mon_nginx.yaml
#kubectl delete hpa monitor-nginx

실행결과는 다음과 같다.

# ./stop-mon_nginx.sh
service "monitor-nginx" deleted
horizontalpodautoscaler.autoscaling "nginx-hpa" deleted
deployment.apps "monitor-nginx" deleted