minikube start
eval $(minikube docker-env)
docker build -t springboot-k8s:1.0 .
kubectl create deployment springboot-k8s --image=springboot-k8s:1.0 --port 8080
deployment.apps/springboot-k8s created
kubectl get deployments
NAME READY UP-TO-DATE AVAILABLE AGE
springboot-k8s 1/1 1 1 3s
kubectl get pods
NAME READY STATUS RESTARTS AGE
springboot-k8s-6f8ddcbb45-wf7kz 1/1 Running 0 11m
kubectl expose deployment springboot-k8s --type=NodePort
service/springboot-k8s exposed
kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 23h
springboot-k8s NodePort 10.109.74.102 <none> 8080:30436/TCP 2m3s
minikube ip
192.168.49.2
http://192.168.49.2:30436/greeting
kubectl get nodes -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
minikube Ready control-plane 23h v1.26.1 192.168.49.2 <none> Ubuntu 20.04.5 LTS 5.15.49-linuxkit docker://20.10.23
kubectl get nodes -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
minikube Ready control-plane 23h v1.26.1 192.168.49.2 <none> Ubuntu 20.04.5 LTS 5.15.49-linuxkit docker://20.10.23
kubectl logs springboot-k8s-6f8ddcbb45-wf7kz
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.6.RELEASE)
2023-02-03 19:50:50.646 INFO 1 --- [ main] c.s.k.s.SpringbootKubernetesApplication : Starting SpringbootKubernetesApplication v0.0.1-SNAPSHOT on springboot-k8s-6f8ddcbb45-wf7kz with PID 1 (/app.jar started by root in /)
2023-02-03 19:50:50.649 INFO 1 --- [ main] c.s.k.s.SpringbootKubernetesApplication : No active profile set, falling back to default profiles: default
2023-02-03 19:50:52.378 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2023-02-03 19:50:52.429 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2023-02-03 19:50:52.430 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.33]
2023-02-03 19:50:52.478 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2023-02-03 19:50:52.478 INFO 1 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1714 ms
2023-02-03 19:50:52.765 INFO 1 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2023-02-03 19:50:53.065 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2023-02-03 19:50:53.069 INFO 1 --- [ main] c.s.k.s.SpringbootKubernetesApplication : Started SpringbootKubernetesApplication in 3.337 seconds (JVM running for 3.89)
kubectl get svc
kubectl pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
springboot-k8s-6f8ddcbb45-gwbmx 1/1 Running 0 5m45s 10.244.0.68 minikube <none> <none>
kubectl scale --replicas=3 deployment/springboot-k8s
kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
springboot-k8s-6f8ddcbb45-dcx9v 1/1 Running 0 4s 10.244.0.69 minikube <none> <none>
springboot-k8s-6f8ddcbb45-gq4p5 1/1 Running 0 4s 10.244.0.70 minikube <none> <none>
springboot-k8s-6f8ddcbb45-gwbmx 1/1 Running 0 9m21s 10.244.0.68 minikube <none> <none>
minikube service springboot-k8s
|-----------|----------------|-------------|---------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|----------------|-------------|---------------------------|
| default | springboot-k8s | 8080 | http://192.168.49.2:30794 |
|-----------|----------------|-------------|---------------------------|
๐ Starting tunnel for service springboot-k8s.
|-----------|----------------|-------------|------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|----------------|-------------|------------------------|
| default | springboot-k8s | | http://127.0.0.1:50941 |
|-----------|----------------|-------------|------------------------|
๐ Opening service default/springboot-k8s in default browser...
โ Because you are using a Docker driver on darwin, the terminal needs to be open to run it.
kubectl get deployments
NAME READY UP-TO-DATE AVAILABLE AGE
springboot-k8s 3/3 3 3 13m
kubectl get pods
NAME READY STATUS RESTARTS AGE
springboot-k8s-6f8ddcbb45-dcx9v 1/1 Running 0 5m21s
springboot-k8s-6f8ddcbb45-gq4p5 1/1 Running 0 5m21s
springboot-k8s-6f8ddcbb45-gwbmx 1/1 Running 0 14m
// to check replicas
kubectl get rs
NAME DESIRED CURRENT READY AGE
springboot-k8s-6f8ddcbb45 3 3 3 16m
minikube dashboard
๐ค Verifying dashboard health ...
๐ Launching proxy ...
๐ค Verifying proxy health ...
๐ Opening http://127.0.0.1:51009/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/ in your default browser...
// when it reached 50% autoscale container
kubectl autoscale deployment springboot-k8s --cpu-percent=50 --min=1 --max=10
horizontalpodautoscaler.autoscaling/springboot-k8s autoscaled
kubectl get hpa
// hpa => horizontalpodautoscaler
kubectl get hpa
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
springboot-k8s Deployment/springboot-k8s <unknown>/50% 1 10 3 46m
kubectl get deployments
NAME READY UP-TO-DATE AVAILABLE AGE
springboot-k8s 3/3 3 3 27m
kubectl get deployments -o wide
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
springboot-k8s 3/3 3 3 27m springboot-k8s springboot-k8s:1.0 app=springboot-k8s
Process to update image:
docker build -t springboot-k8s:2.0 .
kubectl set image deployment springboot-k8s springboot-k8s=springboot-k8s:2.0
kubectl get pods
NAME READY STATUS RESTARTS AGE
springboot-k8s-6f8ddcbb45-dcx9v 1/1 Running 0 22m
springboot-k8s-6f8ddcbb45-gq4p5 1/1 Running 0 22m
springboot-k8s-6f8ddcbb45-gwbmx 1/1 Running 0 31m
kubectl get deployments
NAME READY UP-TO-DATE AVAILABLE AGE
springboot-k8s 3/3 3 3 31m
kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 24h
springboot-k8s NodePort 10.103.28.69 <none> 8080:30794/TCP 32m
kubectl describe rs
kubectl describe deployments
kubectl delete deploy springboot-k8s
kubectl delete svc springboot-k8s
kubectl delete pod springboot-k8s
kubectl apply -f deployment.yml
kubectl apply -f service.yml
kubectl apply -f deployment.yml
deployment.apps/springboot-k8s created
kubectl apply -f service.yml
service/springboot-k8s created
minikube service springboot-k8s
http://127.0.0.1:51293/greeting
kubectl delete deploy springboot-k8s
kubectl delete svc springboot-k8s
kubectl delete pod springboot-k8s
docker rm $(docker ps -a -q) -f
docker rmi $(docker images -a -q) -f
docker ps -a
docker images -a
Deployment is responsible to run a set of pods and service gives network access to these pods
/*
kubectl run springboot-k8s --image=springboot-k8s:1.0 --port 8080 --image-pull-policy=Never
pod/springboot-k8s created
*/