Demo for the second section of Java on Kubernetes: What I wish I knew first presented at Devnexus 2022.
It shows how to obtain a good dev experience for Java on Kubernetes.
For the whole presentation, see presentation
dir.
Authors:
-
Alberto C. Ríos: @albertoimpl on Twitter, Albertoimpl on GitHub
-
Abel Salgado Romero: @abelsromero on Twitter, abelsromero on GitHub
-
Kind: to create a simplified local K8s cluster.
-
Skaffold: to automate, build, deploy and debugging, with life-reload. Debugging requires IntelliJ Cloud Code plugin.
|
deploying in just Docker or local K8s requires the minimal setup, but also require more manual steps. And doesn’t allow for life-reload and code debugging from IntelliJ. |
To run in plain Docker, build the image and run it.
$ ./gradlew bootBuildImage $ docker run -it -p8080:8080 devnexus:0.0.1-SNAPSHOT
-
Start a local Kind cluster
$ kind create cluster --config kind-config.yaml
-
Build Spring Boot docker image
$ ./gradlew bootBuildImage
-
Load image into Kind
$ kind load docker-image devnexus:0.0.1-SNAPSHOT
-
Deploy in Kind’s K8s cluster
$ kubectl apply -f manifests/
To validate it:
$ kubectl port-forward service/devnexus-svc 8080:8080
You should be able to access the Actuator endpoint http://localhost:8080/actuator.
📎
|
Project contains a modified version of https://github.com/kubernetes-sigs/metrics-server/releases/download/metrics-server-helm-chart-3.8.2/components.yaml adding scraper.go:140] "Failed to scrape node" err="Get \"https://172.18.0.2:10250/metrics/resource\": x509: cannot validate certificate for 172.18.0.2 because it doesn't contain any IP SANs" node="kind-21-worker" |
Skaffold automates the complete process of building, deploying, port-forwarding and debugging. It also offers life-reload, so that changes in the code ar automatically deployed in the local k8s cluster.
To just run without debugging
$ skaffold dev
You should be able to access the Actuator endpoint http://localhost:8080/actuator.
For debugging install Cloud Code plugin in IntelliJ.
Create a Cloud Code: Kubernetes
with the Run > Edit Configurations
option, and run it as Debug
.
You should see the app logs in the ID console and be able to add breakpoints and debug as any other Java app.
Skaffold deployment adds metrics server adapted for Kind. Once deployed, you can check the resources used by the pod with
$ kubectl top pods