- 이전 포스팅에서 1.2 까지 진행하기
- AppController.java 생성하기
package com.example.demo; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class AppController { @Value("${MY_ACCOUNT:default}") // `:` 앞 공백 제거 private String myAccount; @Value("${MY_PASSWORD:default}") // `:` 앞 공백 제거 private String myPassword; @GetMapping("/") public String home() { return "myAccount : " + myAccount + ", myPassword : " + myPassword; } }
- DemoApplication.java 실행 후 localhost:8080 접속하기
- build 진행
- 이미지를 생성할 때 기준이 되는 jar파일을 생성한다.
- 도커파일을 바탕으로 이미지 build
- 이미지를 생성할 때 기준이 되는 jar파일을 생성한다.
- spring-deployement.yaml 파일 생성 및 환경 변수 생성하기
apiVersion : apps/v1 kind: Deployment metadata : name : spring-deployment spec: replicas : 3 selector: matchLabels: app: backend-app template: metadata: labels: app: backend-app spec: containers : - name : spring-container image : spring-server imagePullPolicy : IfNotPresent ports: - containerPort: 8080 env: - name: MY_ACCOUNT value: rusharp - name: MY_PASSWORD value: test123!
- 아래의 부분이 환경변수 생성에 해당한다.
- 아래의 부분이 환경변수 생성에 해당한다.
- spring-service.yaml 파일 생성하기
apiVersion : v1 kind: Service metadata: name: spring-service spec: type: NodePort selector: # deployment 파일의 sepc/template/metadata/labels/app 과 동일해야 한다. app: backend-app ports: - protocol : TCP nodePort : 30000 targetPort: 8080 port: 8080
- 오브젝트 생성하기
- 오브젝트 생성 결과 확인하기
- 오브젝트 생성 결과 확인하기
- 서버 접속 및 환경변수 확인
- AppController.java 생성하기
'쿠버네티스 > cka' 카테고리의 다른 글
Pod, deployment, service 개념 정리 (0) | 2025.03.06 |
---|---|
Deployement, service를 활용하여 서버 띄워보기 명령어 정리! (0) | 2025.03.06 |
디플로이먼트, 서비스를 활용해 백엔드(Nest.js) 서버 띄워보기 (0) | 2025.03.06 |
VS code 에서 새로운 버전의 서버로 업데이트 시키기 (0) | 2025.03.05 |
서버가 죽었을 때 자동으로 복구하는 기능 (Self-Healing) (0) | 2025.03.04 |