docs: add kubernetes docker-compose demo (#10)

This commit is contained in:
Matthias Schneider
2021-10-01 18:52:25 +02:00
committed by GitHub
parent 711f6858d2
commit e6cbbcbe60
7 changed files with 205 additions and 1 deletions

View File

@@ -3,7 +3,7 @@ type: middleware
import: github.com/acouvreur/traefik-ondemand-plugin
summary: 'Start your containers/services on the first request they recieve, and shut them down after a specified duration after the last request they received. Docker classic and docker swarm compatible.'
summary: 'Start your containers/services on the first request they recieve, and shut them down after a specified duration after the last request they received. Kubernetes, Docker classic and docker swarm compatible.'
testData:
serviceUrl: http://ondemand:10000

View File

@@ -58,6 +58,7 @@ The docker library that interacts with the docker deamon uses `unsafe` which mus
- [Docker Classic](./examples/docker_classic/)
- [Docker Swarm](./examples/docker_swarm/)
- [Multiple Containers](./examples/multiple_containers/)
- [Kubernetes](./examples/kubernetes/)
## Authors

View File

@@ -0,0 +1,29 @@
# Kubernetes
## Run the demo
# you need docker-compose, kubectl and helm (v3) installed
1. `git clone git@github.com:acouvreur/traefik-ondemand-plugin.git`
2. `cd traefik-ondemand-plugin/examples/kubernetes`
3. `docker-compose up`
4. Wait 1 minute
5. `export KUBECONFIG=./kubeconfig.yaml`
5. `helm repo add traefik https://helm.traefik.io/traefik`
6. `helm repo update`
7. Edit values.yaml and add your traefik pilot.token
8. `helm install traefik traefik/traefik -f values.yaml --namespace kube-system `
9. `kubectl apply -f deploy-whoami.yml`
10. `kubectl apply -f manifests.yml`
11. Browse to http://localhost/
12. `kubectl get deployments -o wide`
```
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
whoami 1/1 1 1 16m whoami containous/whoami app=whoami
```
13. After 1 minute: `kubectl get deployments -o wide`
```
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
whoami 0/0 0 0 17m whoami containous/whoami app=whoami`
```
14. Browse to http://localhost/

View File

@@ -0,0 +1,49 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: whoami
spec:
replicas: 1
selector:
matchLabels:
app: whoami
template:
metadata:
labels:
app: whoami
spec:
containers:
- name: whoami
image: containous/whoami
---
apiVersion: v1
kind: Service
metadata:
name: whoami-service
spec:
ports:
- name: http
targetPort: 80
port: 80
selector:
app: whoami
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: whoami-ingress
annotations:
kubernetes.io/ingress.class: traefik
traefik.ingress.kubernetes.io/router.middlewares: default-ondemand-whoami@kubernetescrd
spec:
rules:
- host: localhost
http:
paths:
- path: /
pathType: ImplementationSpecific
backend:
service:
name: whoami-service
port:
number: 80

View File

@@ -0,0 +1,29 @@
version: '3'
services:
server:
image: "rancher/k3s:${K3S_VERSION:-latest}"
command: server --no-deploy traefik
tmpfs:
- /run
- /var/run
ulimits:
nproc: 65535
nofile:
soft: 65535
hard: 65535
privileged: true
restart: always
environment:
- K3S_KUBECONFIG_OUTPUT=/output/kubeconfig.yaml
- K3S_KUBECONFIG_MODE=666
volumes:
- k3s-server:/var/lib/rancher/k3s
# This is just so that we get the kubeconfig file out
- .:/output
ports:
- 6443:6443 # Kubernetes API Server
- 80:80 # Ingress controller port 80
- 443:443 # Ingress controller port 443
volumes:
k3s-server: {}

View File

@@ -0,0 +1,86 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: traefik-ondemand-service
namespace: kube-system
labels:
app: traefik-ondemand-service
spec:
replicas: 1
selector:
matchLabels:
app: traefik-ondemand-service
template:
metadata:
labels:
app: traefik-ondemand-service
spec:
serviceAccountName: traefik-ondemand-service
serviceAccount: traefik-ondemand-service
containers:
- name: traefik-ondemand-service
image: ghcr.io/acouvreur/traefik-ondemand-service:sha-1d3af8c
args: ["--swarmMode=false", "--kubernetesMode=true"]
ports:
- containerPort: 10000
---
apiVersion: v1
kind: Service
metadata:
name: traefik-ondemand-service
namespace: kube-system
spec:
selector:
app: traefik-ondemand-service
ports:
- protocol: TCP
port: 10000
targetPort: 10000
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: traefik-ondemand-service
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: traefik-ondemand-service
namespace: kube-system
rules:
- apiGroups:
- apps
resources:
- deployments
- deployments/scale
verbs:
- patch
- get
- update
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: traefik-ondemand-service
namespace: kube-system
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: traefik-ondemand-service
subjects:
- kind: ServiceAccount
name: traefik-ondemand-service
namespace: kube-system
---
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: ondemand-whoami
namespace: default
spec:
plugin:
traefik-ondemand-plugin:
name: deployment_default_whoami_1
serviceUrl: 'http://traefik-ondemand-service:10000'
timeout: 1m

View File

@@ -0,0 +1,10 @@
# traefik helm values
additionalArguments:
- "--pilot.token=XXXXX_YOURTOKEN_XXXXXXXXXXXXXXXX"
- "--experimental.plugins.traefik-ondemand-plugin.modulename=github.com/acouvreur/traefik-ondemand-plugin"
- "--experimental.plugins.traefik-ondemand-plugin.version=v0.1.1"
- "--providers.kubernetesingress.allowEmptyServices=true"
experimental:
plugins:
enabled: true