Add simple Kubernetes example

This commit is contained in:
Markus Opolka 2022-07-21 15:05:24 +02:00 committed by PlantUML
parent 2d011e233e
commit 820fcca9ac
3 changed files with 136 additions and 0 deletions

View File

@ -2,3 +2,4 @@
- [Nginx simple reverse proxy example](./nginx-simple)
- [Nginx reverse proxy example with defined location directive (different context path)](./nginx-contextpath)
- [Kubernetes simple deployment](./kubernetes-simple)

View File

@ -0,0 +1,51 @@
# PlantUML Kubernetes Deployment
In this example, PlantUML is deployed on an Kubernetes cluster using a `Deployment`, a `Service` and an `Ingress`.
## Quick start
Install:
```bash
# Hint: Adjust the Ingress host to your URL
kubectl create ns plantuml
kubectl -n plantuml apply -f deployment.yaml
```
Uninstall:
```bash
kubectl -n plantuml delete -f deployment.yaml
kubectl delete ns plantuml
```
## TLS configuration
Create a TLS `Secret` and extend the `Ingress` spec with a TLS configuration:
```bash
[...]
tls:
- hosts:
- plantuml-example.localhost
secretName: plantuml-tls
```
Since the `Ingress Controller` terminates the TLS and routes `http` to the application, we might need to tell the application explicitly that it got a forwarded request.
This configuration changes depending on the `Ingress Controller`. Here an nginx example:
```
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/configuration-snippet: |
more_set_headers "X-Forwarded-Proto: https";
```
## Useful commands
```bash
# see whats going on inside your Deployment
kubectl -n plantuml logs -l "app.kubernetes.io/name=plantuml"
```

View File

@ -0,0 +1,84 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: plantuml
labels:
app.kubernetes.io/name: plantuml
app.kubernetes.io/instance: plantuml
spec:
replicas: 3 # Can be adjusted
selector:
matchLabels:
app.kubernetes.io/name: plantuml
app.kubernetes.io/instance: plantuml
template:
metadata:
labels:
app.kubernetes.io/name: plantuml
app.kubernetes.io/instance: plantuml
spec:
containers:
- name: plantuml
securityContext:
allowPrivilegeEscalation: false
image: plantuml/plantuml-server:jetty-v1.2022.6
imagePullPolicy: Always
# env: # In case of different base URL
# - name: BASE_URL
# value: plantuml
ports:
- name: http
containerPort: 8080
protocol: TCP
livenessProbe:
tcpSocket:
port: http
readinessProbe:
tcpSocket:
port: http
resources:
limits:
cpu: 500m
memory: 2048Mi
requests:
cpu: 250m
memory: 1024Mi
---
apiVersion: v1
kind: Service
metadata:
name: plantuml
labels:
app.kubernetes.io/name: plantuml
app.kubernetes.io/instance: plantuml
spec:
type: ClusterIP
ports:
- port: 80
targetPort: http
protocol: TCP
name: http
selector:
app.kubernetes.io/name: plantuml
app.kubernetes.io/instance: plantuml
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: plantuml
labels:
app.kubernetes.io/name: plantuml
app.kubernetes.io/instance: plantuml
spec:
rules:
- host: plantuml-example.localhost
http:
paths:
- backend:
service:
name: plantuml
port:
number: 80
path: /
pathType: Prefix