A demo app to show how to setup Reactive Spring on Netty, written in Groovy.
$ ./gradlew build
$ DOCKER_BUILDKIT=1 docker build -t com.example/hello-world:1.0.0 .
- Install Docker for Desktop from here: https://www.docker.com/products/docker-desktop
- Activate Kubernetes in Docker preferences (takes 5-10 minutes the first time):
- Confirm Kubernetes installation:
$ kubectl cluster-info
Kubernetes master is running at https://kubernetes.docker.internal:6443
KubeDNS is running at https://kubernetes.docker.internal:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
- Generate YAML:
$ mkdir .kube
$ kubectl create deployment hello-world --image=com.example/hello-world:1.0.0 --dry-run -o yaml >.kube/deployment.yaml
$ cat .kube/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: hello-world
name: hello-world
spec:
replicas: 1
selector:
matchLabels:
app: hello-world
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: hello-world
spec:
containers:
- image: com.example/hello-world:1.0.0
name: hello-world
resources: {}
status: {}
- Apply deployment:
$ kubectl apply -f .kube/deployment.yaml
deployment.apps/hello-world created
$ kubectl port-forward deployment/hello-world 8080
Forwarding from 127.0.0.1:8080 -> 8080
Forwarding from [::1]:8080 -> 8080
Test the application by browsing to http://localhost:8080
- Update replicas from 1 to 2 in
.kube/deployment.yaml
- Redeploy with:
kubectl apply -f .kube/deployment.yaml
- Generate YAML:
$ kubectl create service clusterip hello-world --tcp=8080:8080 --dry-run -o yaml >.kube/service.yaml
$ cat .kube/service.yaml
apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
labels:
app: hello-world
name: hello-world
spec:
ports:
- name: 8080-8080
port: 8080
protocol: TCP
targetPort: 8080
selector:
app: hello-world
type: ClusterIP
status:
loadBalancer: {}
- Apply service:
$ kubectl apply -f .kube/service.yaml
service/hello-world created
$ kubectl port-forward svc/hello-world 8080
Forwarding from 127.0.0.1:8080 -> 8080
Forwarding from [::1]:8080 -> 8080
Test the application by browsing to http://localhost:8080
- Add
app.host: ${HOSTNAME}
to application.yaml - Add
String host
to Application.Config - Add
${host}
somewhere in the template
- Build a new Docker image:
DOCKER_BUILDKIT=1 docker build -t com.example/hello-world:1.0.1 .
- Update 1.0.0 to 1.0.1 in
.kube/deployment.yaml
- Redeploy with:
kubectl apply -f .kube/deployment.yaml
- Reload http://localhost:8080 a few times and confirm round-robin load balancing.
- Generate a ConfigMap:
$ kubectl create configmap hello-world --from-literal=app.name=Jim --dry-run -o yaml >.kube/config.yaml
$ cat .kube/config.yaml
apiVersion: v1
data:
app.name: Jim
kind: ConfigMap
metadata:
creationTimestamp: null
name: hello-world
- Apply the ConfigMap:
$ kubectl apply -f .kube/config.yaml
configmap/hello-world configured
- Add `org.springframework.cloud:spring-cloud-starter-kubernetes-config:1.1.1.RELEASE' as a Gradle dependency
- Remove
app.name
reference fromapplication.yaml
- Build a new Docker image and update the deployment
- Install NGINX Ingress Controller (see: https://kubernetes.github.io/ingress-nginx/deploy):
$ kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.29.0/deploy/static/mandatory.yaml
$ kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.29.0/deploy/static/provider/cloud-generic.yaml
- Create the file .kube/ingress.yaml:
$ cat .kube/ingress.yaml
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: hello-world
spec:
backend:
serviceName: hello-world
servicePort: 8080
- Apply ingress:
$ kubectl apply -f .kube/ingress.yaml
ingress.networking.k8s.io/hello-world created
- Generate a Helm chart:
$ helm create .kube/hello-world
Creating .kube/hello-world
- Replace the contents of
templates
with the YAML files in.kube
- Delete
values.yaml
because we will supply values at install time. - Externalize our name parameter. In
config.yaml
changeVictor
to{{ .Values.Name }}
- Add NGINX as a chart dependency by adding the following to Chart.yaml:
dependencies:
- name: nginx-ingress
version: 1.31.0
repository: https://kubernetes-charts.storage.googleapis.com/
- Install NGINX chart with:
$ cd .kube/hello-world && helm dependency update
- Delete all resources that we've previously installed:
$ kubectl delete ingress/hello-world configmap/hello-world svc/hello-world deploy/hello-world
$ kubectl delete ns/ingress-nginx
- Install the new Helm chart:
$ helm install --set Name=Steve hello-world .kube/hello-world