쿠버네티스에서 여러 개의 서비스나 애플리케이션을 운영할 때 각각을 별도의 Deployment로 정의하는 것이 일반적입니다. 따라서 Spring Boot 애플리케이션을 위한 별도의 Deployment YAML 파일을 작성하여 새로운 애플리케이션을 배포할 수 있습니다.

  1. 젠킨스 Deployment YAML 파일: jenkins-deployment.yaml
  2. Spring Boot 애플리케이션 Deployment YAML 파일: spring-app-deployment.yaml

jenkins-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: jenkins
  namespace: devops-tools
spec:
  replicas: 1
  selector:
    matchLabels:
      app: jenkins-server
  template:
    metadata:
      labels:
        app: jenkins-server
    spec:
      securityContext:
            fsGroup: 1000
            runAsUser: 1000
      serviceAccountName: jenkins-admin
      containers:
        - name: jenkins
          image: jenkins/jenkins:lts
          resources:
            limits:
              memory: "2Gi"
              cpu: "1000m"
            requests:
              memory: "500Mi"
              cpu: "500m"
          ports:
            - name: httpport
              containerPort: 8080
            - name: jnlpport
              containerPort: 50000
          livenessProbe:
            httpGet:
              path: "/login"
              port: 8080
            initialDelaySeconds: 90
            periodSeconds: 10
            timeoutSeconds: 5
            failureThreshold: 5
          readinessProbe:
            httpGet:
              path: "/login"
              port: 8080
            initialDelaySeconds: 60
            periodSeconds: 10
            timeoutSeconds: 5
            failureThreshold: 3
          volumeMounts:
            - name: jenkins-data
              mountPath: /var/jenkins_home
      volumes:
        - name: jenkins-data
          persistentVolumeClaim:
              claimName: jenkins-pv-claim

spring-app-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-spring-app
  namespace: devops-tools
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-spring-app
  template:
    metadata:
      labels:
        app: my-spring-app
    spec:
      containers:
        - name: spring-app
          image: wlsdks12/string-server:0.0.2
          imagePullPolicy: Always
          ports:
            - containerPort: 8080
              protocol: TCP
          resources:
            requests:
              cpu: 500m
              memory: 1000Mi

3번 글로가서 스프링 부트 배포를 확인해보도록 하자