https://yogeshpatel.hashnode.dev/hello-world-in-kubernetes
위 링크를 참고
1.1 ~ 1.2는 아래 방법으로 변경
1.1
Select maven, java(8), jar and add spring web dependency
1.2 새로운 HelloWorldController.java 파일 생성 및 아래 코드 추가
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestMethod;
@RestController
public class HelloWorldController {
@RequestMapping(value = "hello-world", method= RequestMethod.GET)
public String sayHello() {
return "hello world";
}
}
1.3
mvn clean install
1.4
java -jar target/demo-0.0.1-SNAPSHOT.jar
1.5 test in your web browser
http://localhost:8080/hello-world
2.1 Dockerfile 생성
vi Dockerfile
아래 코드 추가 및 저장
2.2 docker-entrypoint.sh 생성
#!/bin/bash
java -jar /opt/app/app.jar
2.3 Docker build
docker build -t demo:1.0.0 .
2.4 check docker image in registry
docker images
2.5 run docker image
docker run -p 8081:8080 -d --name=hello-world-1 -t demo:1.0.0
2.6 docker process check run or not
docker ps
2.7 show docker logs
docker logs hello-world-1
2.8 test in your web browser
http://localhost:8080/hello-world
2.9 Stop docker container
docker stop hello-world-1
3.1 Create deployment.yaml file
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-world-deployment
namespace: default
labels:
app: hello-world
spec:
replicas: 3
selector:
matchLabels:
app: hello-world
template:
metadata:
labels:
app: hello-world
spec:
containers:
- name: hello-world
image: ijung075/demo:1.0.0
ports:
- containerPort: 80
3.2 docker login
docker login
3.3 docker build
ijung075: docker hub의 user name
docker build --tag ijung075/demo:1.0.0 .
3.4 puch image to docker hub
docker push ijung075/demo:1.0.0
docker hub 에 접속하여 image push 되었는지 확인
3.5 apply
kubectl apply -f ./deployment.yaml
3.6 pod check
kubectl get pods -A
3.7 To check logs of a specific pod
kubectl logs hello-world-deployment-cbd86776-29flx
3.8 Expose pod to outside cluster. (여기부터 안됨)
kubectl expose pod hello-world --type=LoadBalancer --port=8080 --target-port=8080
3.9 extneral ip 확인
kubectl get service
3.10 test
http://ip:8080/hello-world
k8sobjectsreceiver 사용방법 (1) | 2023.10.05 |
---|---|
Detector message sample format (0) | 2023.08.21 |
AWS Auto Scaling Group 개수가 안맞는 현상 (0) | 2023.05.18 |
Alert message 전송시 metric의 custom property 값 활용 (0) | 2023.04.03 |
Otel Collector 를 통한 Health Checker (0) | 2023.03.27 |
댓글 영역