MON Operation Overview
K8s 기반의 Node.js API Front-End System Overview
K8s Deployment Current Status
# kubectl get pods -o wide |grep monitor-nodejs
monitor-nodejs-f68967947-qz7bm 1/1 Running 0 5d23h 10.244.4.6 tb3-docker <none> <none>
monitor-nodejs-f68967947-vrchl 1/1 Running 0 5d23h 10.244.4.5 tb3-docker <none> <none>
Node.js Deployment yaml
역할 : Node.js API POD를 배포하는 Deployment를 작성한다.
# cat mon_nodejs.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: nodejs
name: monitor-nodejs
spec:
replicas: 2
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
selector:
matchLabels:
app: nodejs
template:
metadata:
labels:
app: nodejs
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: servertype
operator: NotIn
values:
- master
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- nodejs
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.252
containers:
- image: harbor.hongsnet.net/monitor/monitoring-nodejs:20220801_24
imagePullPolicy: IfNotPresent
name: monitor-nodejs
volumeMounts:
- mountPath: /home
name: mon-home-volume
imagePullSecrets:
- name: harbor-login
Node.js API HPA Scale yaml
역할 : AutoScaling 정책을 작성한다.
# cat mon_scale_nodejs.yaml
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: nodejs-hpa
namespace: default
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: monitor-nodejs
minReplicas: 2
maxReplicas: 3
targetCPUUtilizationPercentage: 50
Node.js API Service yaml
역할 : Node.js API Service를 작성한다. 여기서는 NodePort 방식을 통해 배포한다.
# cat mon_service_nodejs.yaml
apiVersion: v1
kind: Service
metadata:
name: monitor-nodejs
spec:
externalTrafficPolicy: Local
type: NodePort
selector:
app: nodejs
ports:
- name: nodejs
port: 8081
targetPort: 8081
nodePort: 32001
실행
배포 및 관리는 여러 가지 방법이 있지만, 여기서는 kubectl 을 사용하여 실행한다.
- 시작 스크립트
# cat start-mon_nodejs.sh
#!/bin/bash
kubectl create -f mon_nodejs.yaml
kubectl create -f mon_scale_nodejs.yaml
kubectl create -f mon_service_nodejs.yaml
실행결과는 다음과 같다.
# ./start-mon_nodejs.sh
deployment.apps/monitor-nodejs created
horizontalpodautoscaler.autoscaling/nodejs-hpa created
service/monitor-nodejs created
- 중지 스크립트
# cat stop-mon_nodejs.sh
#!/bin/bash
kubectl delete -f mon_service_nodejs.yaml
kubectl delete -f mon_scale_nodejs.yaml
kubectl delete -f mon_nodejs.yaml
실행결과는 다음과 같다.
# ./stop-mon_nodejs.sh
service "monitor-nodejs" deleted
horizontalpodautoscaler.autoscaling "nodejs-hpa" deleted
deployment.apps "monitor-nodejs" deleted