GangHun-Jo / WhatDoYouWant

웹 / 앱 서비스 제안 및 팀 빌딩 플랫폼
0 stars 0 forks source link

Kubernetes 오브젝트 #6

Open GangHun-Jo opened 3 years ago

GangHun-Jo commented 3 years ago

Client Service, Deployment

apiVersion: v1
kind: Service
metadata:
  name: wdyw-svc-{{ .Release.Name }}
spec:
  selector:
    app: wdyw-app-{{ .Release.Name }}
  ports:
    - name: client
      protocol: TCP
      port: 3000
      targetPort: 3000
    - name: server
      protocol: TCP
      port: 8080
      targetPort: 8080
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: wdyw-app-{{ .Release.Name }}
spec:
  replicas: 1
  revisionHistoryLimit: 0
  selector:
    matchLabels:
      app: wdyw-app-{{ .Release.Name }}
  template:
    metadata:
      labels:
        app: wdyw-app-{{ .Release.Name }}
    spec:
      containers:
        - name: client
          image: kanghun8871/wdyw:client
          ports:
            - containerPort: 3000
          imagePullPolicy: Always
        - name: server
          image: kanghun8871/wdyw:server
          ports:
            - containerPort: 8080
          imagePullPolicy: Always
          env:
            - name: DB_HOST
              value: mysql-svc-{{ .Release.Name }}
            - name: DB_NAME
              value: {{ .Values.mysql.db }}
            - name: DB_USER
              value: {{ .Values.mysql.user }}
            - name: DB_PASSWORD
              value: {{ .Values.mysql.password }}
      imagePullSecrets:
        - name: regcred

NGinx ingress

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: wdyw-ingress-{{ .Release.Name }}
  annotations:
    kubernetes.io/ingress.class: "nginx"
    ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
    - http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              serviceName: wdyw-svc-{{ .Release.Name }}
              servicePort: 3000
          - path: /api/v1
            pathType: Prefix
            backend:
              serviceName: wdyw-svc-{{ .Release.Name }}
              servicePort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: ingress-nginx-{{ .Release.Name }}
spec:
  selector:
    app.kubernetes.io/name: intress-nginx-{{ .Release.Name }}
    app.kubernetes.io/part-of: intress-nginx-{{ .Release.Name }}
  ports:
    - targetPort: http
      port: 80
      name: http
    - targetPort: https
      port: 443
      name: https
  type: LoadBalancer
GangHun-Jo commented 3 years ago

mysql

apiVersion: v1
kind: Service
metadata:
  name: mysql-svc-{{ .Release.Name }}
spec:
  ports:
    - port: 3306
  selector:
    app: mysql-{{ .Release.Name }}
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql-{{ .Release.Name }}
spec:
  selector:
    matchLabels:
      app: mysql-{{ .Release.Name }}
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: mysql-{{ .Release.Name }}
    spec:
      containers:
        - image: mysql:5.6
          name: mysql
          env:
            - name: MYSQL_DATABASE
              value: {{ .Values.mysql.db }}
            - name: MYSQL_ROOT_PASSWORD
              value: {{ .Values.mysql.password }}
          ports:
            - containerPort: 3306
              name: mysql
          volumeMounts:
            - name: mysql-persistent-storage
              mountPath: /var/lib/mysql
      volumes:
        - name: mysql-persistent-storage
          persistentVolumeClaim:
            claimName: mysql-pv-claim