liveBook · Manning

Kubernetes

As explained in Spring in Action, Sixth Edition

Kubernetes is a container orchestration platform that manages deployment, scaling, networking, and lifecycle operations for containerized applications.

Kubernetes runs container images, scales containers up or down, and replaces broken ones. For a Spring Boot application headed to a Kubernetes environment, build a container image rather than a traditional server-oriented WAR file. You need a Kubernetes cluster, whether hosted or local, before deploying it. section 18.1 section 18.3.1

apiVersion: apps/v1
kind: Deployment
metadata:
  name: taco-cloud-deploy
  labels:
    app: taco-cloud
spec:
  replicas: 3
  selector:
    matchLabels:
      app: taco-cloud
  template:
    metadata:
      labels:
        app: taco-cloud
    spec:
      containers:
      - name: taco-cloud-container
        image: tacocloud/tacocloud:latest

A deployment manifest is a YAML file describing what to run. This example names the deployment, selects the taco-cloud image, and requests three replicas. Save it as deploy.yaml; then run kubectl apply -f deploy.yaml to submit it to the cluster. section 18.3.1

Check the result with kubectl get all. In the example output, three pods are Running and the deployment reports 3/3 available. For a quick local connection to one pod, kubectl port-forward pod/taco-cloud-deploy-555bd8fdb4-dln45 8080:8080. section 18.3.1

A running application may still be unable to serve requests. Kubernetes uses separate probes for these cases: liveness asks whether to restart a pod; readiness asks whether to send it traffic. During initialization, an application can remain alive but report that it is not ready. section 18.3.3

management:
  health:
    probes:
      enabled: true

Enable Spring Boot Actuator’s liveness and readiness health groups with this application.yml setting. section 18.3.3

apiVersion: apps/v1
kind: Deployment
metadata:
  name: taco-cloud-deploy
  labels:
    app: taco-cloud
spec:
  replicas: 3
  selector:
    matchLabels:
      app: taco-cloud
  template:
    metadata:
      labels:
        app: taco-cloud
    spec:
      containers:
      - name: taco-cloud-container
        image: tacocloud/tacocloud:latest
        livenessProbe:
          initialDelaySeconds: 2
          periodSeconds: 5
          httpGet:
            path: /actuator/health/liveness
            port: 8080
        readinessProbe:
          initialDelaySeconds: 2
          periodSeconds: 5
          httpGet:
            path: /actuator/health/readiness
            port: 8080

Add these HTTP probes to the deployment manifest so Kubernetes checks /actuator/health/liveness and /actuator/health/readiness on port 8080. Both checks start after two seconds and repeat every five seconds. section 18.3.3

How Spring in Action, Sixth Edition covers it

How deep it goes
Walks through a deployment manifest, kubectl checks, and health probes, but defers detailed Kubernetes deployment specifications.
Examples
Uses a three-replica Spring Boot deployment, kubectl output, port forwarding, and HTTP health-probe configuration.
What it assumes
Assumes a Spring Boot container image and an available Kubernetes cluster; defines the deployment manifest and probe roles as needed.
What you can do after
Operate/configure it by deploying a Spring Boot image, checking its pods, and wiring liveness and readiness probes.
How it connects
Links container images and deployment manifests with Spring Boot Actuator health groups, liveness probes, and readiness probes.

Also explained in

Compare how 22 books explain Kubernetes →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring in Action, Sixth Edition. The section links point to the parts of the book it draws on.