Skip to content

Instantly share code, notes, and snippets.

@ErickWendel
Created June 22, 2024 20:22
Show Gist options
  • Save ErickWendel/d8104c8d34e4d4147dec98847682963c to your computer and use it in GitHub Desktop.
Save ErickWendel/d8104c8d34e4d4147dec98847682963c to your computer and use it in GitHub Desktop.
example of using Kubernetes with traefik and lets encrypt to generate SSL Certificates (without the need of adding any additional cluster issuer)
apiVersion: v1
kind: Service
metadata:
name: app
namespace: default
spec:
selector:
app: app
ports:
- protocol: TCP
name: web
port: 80
targetPort: 80
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: app-deployment
namespace: default
labels:
app: app
spec:
replicas: 1
selector:
matchLabels:
app: app
template:
metadata:
labels:
app: app
spec:
containers:
- name: app
image: nginx:latest
ports:
- containerPort: 80
---
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
name: nginx-secure
spec:
entryPoints:
- websecure
routes:
- match: Host(`nginx.erickwendel.com.br`)
kind: Rule
services:
- name: app
port: 80
tls:
certResolver: letsencrypt
additionalArguments:
- "--metrics.prometheus=true"
- "--metrics.prometheus.entryPoint=metrics"
- "--metrics.prometheus.buckets=0.1,0.3,1.2,5.0"
persistence:
enabled: true
accessMode: ReadWriteOnce
size: 128Mi
storageClass: "managed-csi"
path: /data
name: traefik
certResolvers:
letsencrypt:
email: [email protected]
caServer: https://acme-v02.api.letsencrypt.org/directory # Production server
# caServer: https://acme-staging-v02.api.letsencrypt.org/directory # Staging server
httpChallenge:
entryPoint: web
storage: /data/acme.json
deployment:
initContainers:
- name: volume-permissions
image: busybox:latest
command: ["sh", "-c", "ls -la /; touch /data/acme.json; chmod -v 600 /data/acme.json"]
volumeMounts:
- mountPath: /data
name: traefik
podSecurityContext:
fsGroup: 65532
fsGroupChangePolicy: "OnRootMismatch"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment