Skip to content

Commit

Permalink
create example for issues spring-projects/spring-boot#26627
Browse files Browse the repository at this point in the history
  • Loading branch information
gmariotti committed May 21, 2021
1 parent d30f1cc commit 315f582
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 4 deletions.
18 changes: 17 additions & 1 deletion README.md
@@ -1 +1,17 @@
# Spring Boot Prometheus Bug
# Spring Boot Bug

Refers to issue: https://github.com/spring-projects/spring-boot/issues/26627

How to run it:
- Make sure to have kind installed and create the cluster using kind-with-registry.sh
- Build the docker image with `./gradlew jibDockerBuild`
- Run the following docker commands to make the image available in the cluster
- `docker tag spring-boot-bug:2.4.6 localhost:5000/spring-boot-bug:2.4.6`
- `docker push localhost:5000/spring-boot-bug:2.4.6`
- Apply the k8s resources with:
- `kubectl -f apply kubernetes/configmap`
- `kubectl -f apply kubernetes/deployment`

To build the image for a different version of spring-boot:
- Change the `version` in the `build.gradle.kts` file
- Change the `image` tag in the `kubernetes/deployment.yaml` file
9 changes: 6 additions & 3 deletions build.gradle.kts
@@ -1,16 +1,19 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm") version "1.4.10"
id("org.jetbrains.kotlin.plugin.spring") version "1.4.10"
kotlin("jvm") version "1.4.32"
id("org.jetbrains.kotlin.plugin.spring") version "1.4.32"
id("com.google.cloud.tools.jib") version "3.0.0"
}

repositories {
mavenCentral()
}

version = "2.4.6"

dependencies {
implementation(platform("org.springframework.boot:spring-boot-dependencies:2.4.0"))
implementation(platform("org.springframework.boot:spring-boot-dependencies:$version"))

implementation("io.micrometer:micrometer-registry-prometheus")
implementation("org.springframework.boot:spring-boot-starter-actuator")
Expand Down
41 changes: 41 additions & 0 deletions kind-with-registry.sh
@@ -0,0 +1,41 @@
#!/bin/sh
set -o errexit

# create registry container unless it already exists
reg_name='kind-registry'
reg_port='5000'
running="$(docker inspect -f '{{.State.Running}}' "${reg_name}" 2>/dev/null || true)"
if [ "${running}" != 'true' ]; then
docker run \
-d --restart=always -p "127.0.0.1:${reg_port}:5000" --name "${reg_name}" \
registry:2
fi

# create a cluster with the local registry enabled in containerd
cat <<EOF | kind create cluster --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
containerdConfigPatches:
- |-
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:${reg_port}"]
endpoint = ["http://${reg_name}:${reg_port}"]
EOF

# connect the registry to the cluster network
# (the network may already be connected)
docker network connect "kind" "${reg_name}" || true

# Document the local registry
# https://github.com/kubernetes/enhancements/tree/master/keps/sig-cluster-lifecycle/generic/1755-communicating-a-local-registry
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: ConfigMap
metadata:
name: local-registry-hosting
namespace: kube-public
data:
localRegistryHosting.v1: |
host: "localhost:${reg_port}"
help: "https://kind.sigs.k8s.io/docs/user/local-registry/"
EOF

9 changes: 9 additions & 0 deletions kubernetes/configmap.yaml
@@ -0,0 +1,9 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: spring-boot-application
labels:
app: spring-boot-application
data:
application-kubernetes.yml: |
server.port: 8080
74 changes: 74 additions & 0 deletions kubernetes/deployment.yaml
@@ -0,0 +1,74 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: spring-boot-application
labels:
app: spring-boot-application
spec:
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
type: RollingUpdate
replicas: 1
selector:
matchLabels:
app: spring-boot-application
template:
metadata:
labels:
app: spring-boot-application
spec:
securityContext:
runAsNonRoot: true
runAsUser: 65534
runAsGroup: 65534
# needed because of https://github.com/aws/amazon-eks-pod-identity-webhook/issues/8
fsGroup: 65534
containers:
- name: spring-boot-application
image: "localhost:5000/spring-boot-bug:2.4.6"
imagePullPolicy: Always
env:
- name: JAVA_TOOL_OPTIONS
value: "-XX:+UseContainerSupport -XX:InitialRAMPercentage=50 -XX:MaxRAMPercentage=80"
- name: SPRING_PROFILES_ACTIVE
value: "kubernetes"
ports:
- containerPort: 8080
name: http
protocol: TCP
livenessProbe:
failureThreshold: 5
httpGet:
path: /actuator/health/liveness
port: http
initialDelaySeconds: 10
periodSeconds: 3
successThreshold: 1
timeoutSeconds: 5
readinessProbe:
failureThreshold: 5
httpGet:
path: /actuator/health/readiness
port: http
initialDelaySeconds: 10
periodSeconds: 3
successThreshold: 1
timeoutSeconds: 5
volumeMounts:
- name: tmp
mountPath: /tmp
- name: spring-boot-application
mountPath: /config
readOnly: true
securityContext:
privileged: false
readOnlyRootFilesystem: true
restartPolicy: Always
volumes:
- name: tmp
emptyDir: { }
- name: spring-boot-application
configMap:
name: spring-boot-application

0 comments on commit 315f582

Please sign in to comment.