k8s 프론트엔드 배포 관련 yaml 파일

icdev·2025년 5월 20일

infra

목록 보기
4/5

config map

nginx-config

apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx-config
data:
  default.conf: | 
    upstream backend {
		      #ip_hash; #스티키 세션으로 연결시키기
		      server back-svc:8080;
		}
		
		server {
		        listen 80 default_server;
		        listen [::]:80 default_server;
		
		        root /usr/share/nginx/html;
		
		        index index.html index.htm index.nginx-debian.html;
		
		        server_name _;
		
		        location / {
		                try_files $uri $uri/ /index.html;
		        }
		
		
		        location /api {
		            rewrite ^/api(/.*)$ $1 break;
		            proxy_pass http://backend;  # 업스트림 그룹으로 프록시
		            proxy_set_header Host $host;
		            proxy_set_header X-Real-IP $remote_addr;
		            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		            proxy_set_header X-Forwarded-Proto $scheme;
		        }
		
		        location /ws {
		                proxy_pass http://backend;
		                proxy_http_version 1.1;
		                proxy_set_header Upgrade $http_upgrade;
		                proxy_set_header Connection \"upgrade\";
		        }
		
		}

Deployment or Rollout

nginx Deployment

특별히 argocd의 Rollout을 쓰는게 아니라면 Deployment로

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
  labels:
    type: frontend
spec:
  replicas: 1
  selector:
    matchLabels:
      type: frontend
  template:
    metadata:
      labels:
        type: frontend
    spec:
      initContainers:
        - name : init-html
          image: busybox
          command: ["sh", "-c", "echo test > /usr/share/nginx/html/test.html"]
          volumeMounts:
            - name: nginx-vol
              mountPath: /usr/share/nginx/html
      containers:
        - name: nginx
          image: nginx:latest
          volumeMounts:
            - name: nginx-vol
              mountPath: /usr/share/nginx/html
            - name: config
              mountPath: /etc/nginx/conf.d/
          ports:
            - containerPort: 80
      volumes:
        - name: nginx-vol
          persistentVolumeClaim:
            claimName: nginx-pvc
        - name: config
          configMap:
            name: nginx-config

nginx Rollout

Service

NodePort Service

apiVersion: v1
kind: Service
metadata:
  name: front-svc
spec:
  selector:
    type: frontend
  ports:
  - port: 80
    targetPort: 80
  type:  NodePort # LoadBalancer 도 가능

0개의 댓글