- 本專案主要針對kubernates的教學進行學習、測試以及紀錄
- 建立Spring boot專案
- 產生docker image
- 使用kubernetes minikube對外溝通
- Minikube
brew install minikube
brew install kubectl
- 下載上述工具
- 打開Spring boot專案
- 使用Maven install產生target資料夾HappyDemo-0.0.1-SNAPSHOT.jar
- 新增docker file(如下)
- 修改image tag 為自己docker account/app名字(lnc2244/happy-demo)並產生local image
- push to repository
(terminal)
- 開啟minikube 並create deployment(pod)
minikube start
8. 編輯.yaml檔案以產生deployment/pods(如下)
- 啟用.yaml檔案
kubectl apply -f happy-app-deployment.yaml
- 檢查pods中的application是否正常運作
kubectl logs [pods name]
minikube tunnel
kubectl expose deployment happyapp --name=happyapp-service --port --target-pirt=8080 --type=LoadBalancer
- 取得對外溝通localhost
minikube service happyapp-service --url
--> http://127.0.0.1:56506
13. 在瀏覽器中輸入[localhost]/[springboot url]
FROM openjdk:17-jdk
VOLUME /tmp
COPY target/HappyDemo-0.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT ["java", "-jar", "/app.jar"]
kind: Deployment
apiVersion: apps/v1
metadata:
name: happyapp
labels:
app: happyapp
spec:
replicas: 2
selector:
matchLabels:
app: happyapp
template:
metadata:
labels:
app: happyapp
spec:
containers:
- name: happy-demo
image: lnc2244/happy-demo
ports:
- containerPort: 80