Skip to content

abelsromero/devnexus22

Repository files navigation

Devnexus 22: 'Java on Kubernetes: What I wish I knew first' tools demo

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:

Requirements

Build & Deploy

⚠️
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.

Docker only

To run in plain Docker, build the image and run it.

$ ./gradlew bootBuildImage
$ docker run -it -p8080:8080 devnexus:0.0.1-SNAPSHOT

Kubernetes (from scratch)

  1. Start a local Kind cluster

    $ kind create cluster --config kind-config.yaml
  2. Build Spring Boot docker image

    $ ./gradlew bootBuildImage
  3. Load image into Kind

    $ kind load docker-image devnexus:0.0.1-SNAPSHOT
  4. 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 --kubelet-insecure-tls. Without this change metrics-server pod won’t start with error

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

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.

Running in minikube

$ minikube start --kubernetes-version=v1.21.10

Features

Metrics

Skaffold deployment adds metrics server adapted for Kind. Once deployed, you can check the resources used by the pod with

$ kubectl top pods

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages