INGRESS, SERVICE, DEPLOYMENT 배포



  • Category : Kubernetes
  • Tag : Azure


사전준비

kubectx 명령어 설치

git clone https://github.com/ahmetb/kubectx.git ~/.kubectx
export PATH=$PATH:~/.kubectx
source ~/.bashrc  # 또는 Zsh를 사용 중이라면 ~/.zshrc

node1 = frontend, node2 = backend환경 지정

kubectl label nodes node1 environment=frontend
kubectl label nodes node2 environment=backend

node에 지정한 레이블 확인

kubectl get nodes --show-labels

namespace 생성

kubectl create namespace frontend
kubectl create namespace backend

지정한 레이블명 삭제

kubectl label nodes node1 environment-
kubectl label nodes node2 environment-

FRONT 배포

deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: front-app
  namespace: frontend
spec:
  replicas: 1
  selector:
    matchLabels:
      app: front-app
  template:
    metadata:
      labels:
        app: front-app
    spec:
      nodeSelector:
        environment: frontend
      containers:
        - name: xforwardedfor
          image: iiblackcode/postgre:kbhc
          ports:
            - containerPort: 8080

Service.yaml 배포

apiVersion: v1
kind: Service
metadata:
  name: front-service
  namespace: frontend
spec:
  selector:
    # name: spring-boot-app  # Pod와 연결할 라벨 셀렉터
    app: front-app  # Pod와 연결할 라벨 셀렉터
  ports:
    - protocol: TCP
      port: 80  # 서비스가 노출하는 포트
      targetPort: 8080  # 서비스로 전달되는 트래픽을 받을 Pod의 포트
      # nodePort: 30080
  # type: ClusterIP  # 클러스터 내에서만 사용 가능한 서비스
  # type: NodePort # Node의 IP주소를 통해 접근 가능한 서비스
  type: LoadBalancer # 외부 트래픽도 전달할 수 있는 서비스

Ingress.yaml 배포

# apiVersion: networking.k8s.io/v1 kubernetes 1.19이상 버전에서 사용가능
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: front-ingress
  namespace: frontend
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
    # appgw.ingress.kubernetes.io/use-private-ip: "true"
    # appgw.ingress.kubernetes.io/health-probe-path: /index.html
spec:
  rules:
    - host:  "blackcode.site" # 외부 도메인을 지정
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              serviceName: front-service
              servicePort: 80 # NodePort 서비스의 포트를 80으로 설정

Share this post