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

logo

MON Operation Overview

K8s 기반의 Node.js DB API Front-End System Overview

K8s Deployment Current Status

# kubectl get pods -o wide |grep monitor-dbapi
monitor-dbapi-74cb655d-8lxzb             1/1     Running   0          5d23h   10.244.4.7     tb3-docker   <none>           <none>
monitor-dbapi-74cb655d-grngk             1/1     Running   0          5d23h   10.244.3.253   tb3          <none>           <none>

Node.js DB API Deployment yaml

역할 : Node.js DB API POD를 배포하는 Deployment를 작성한다.

# cat mon_nodejs_db.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: dbapi
  name: monitor-dbapi
spec:
  replicas: 2
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
  selector:
    matchLabels:
      app: dbapi
  template:
    metadata:
      labels:
        app: dbapi
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: servertype
                operator: NotIn
                values:
                - master
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: app
              #- key: servertype
                operator: In
                values:
                - dbapi
            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-nodejs-db:20220801_6
        imagePullPolicy: IfNotPresent
        name: monitor-dbapi
        volumeMounts:
         - mountPath: /home
           name: mon-home-volume
      imagePullSecrets:
        - name: harbor-login

Node.js DB API HPA Scale yaml

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

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

Node.js DB API Service yaml

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

# cat mon_service_nodejs_db.yaml
apiVersion: v1
kind: Service
metadata:
  name: monitor-dbapi
spec:
  externalTrafficPolicy: Local
  type: NodePort
  selector:
    app: dbapi
  ports:
    - name: dbapi
      port: 8900
      targetPort: 8900
      nodePort: 32002

실행

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

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

kubectl create -f mon_nodejs_db.yaml
kubectl create -f mon_scale_nodejs_db.yaml
kubectl create -f mon_service_nodejs_db.yaml

실행결과는 다음과 같다.

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

kubectl delete -f mon_service_nodejs_db.yaml
kubectl delete -f mon_scale_nodejs_db.yaml
kubectl delete -f mon_nodejs_db.yaml

실행결과는 다음과 같다.

# ./stop-mon_nodejs_db.sh
service "monitor-dbapi" deleted
horizontalpodautoscaler.autoscaling "dbapi-hpa" deleted
deployment.apps "monitor-dbapi" deleted