-
Notifications
You must be signed in to change notification settings - Fork 2
/
k8s-install.sh
66 lines (55 loc) · 1.61 KB
/
k8s-install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
DEVBOX_HOSTNAME=${DEVBOX_HOSTNAME:-dev.localhost}
DEVBOX_ISSUER=${DEVBOX_ISSUER:-mkcert}
# allows to switch to kind
TRAEFIK_MODE=${TRAEFIK_MODE:-local}
echo "---------------------------------------------"
echo "-- traefik/k8s-install.sh : "
echo "-- DEVBOX_HOSTNAME=${DEVBOX_HOSTNAME}"
echo "-- DEVBOX_ISSUER=${DEVBOX_ISSUER}"
echo "-- TRAEFIK_MODE=${TRAEFIK_MODE}"
echo "---------------------------------------------"
# Add helm repository
helm repo add traefik https://helm.traefik.io/traefik
# Update helm repositories
helm repo update
# Create namespace traefik-system if not exists
kubectl create namespace traefik-system --dry-run=client -o yaml | kubectl apply -f -
# Deploy traefik with helm
helm -n traefik-system upgrade --install traefik traefik/traefik \
-f ${SCRIPT_DIR}/helm/${TRAEFIK_MODE}/values.yml
# Create Certificate using cert-manager
cat <<EOF | kubectl -n traefik-system apply -f -
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: traefik-cert
spec:
secretName: traefik-tls
issuerRef:
name: ${DEVBOX_ISSUER}
kind: ClusterIssuer
dnsNames:
- traefik.$DEVBOX_HOSTNAME
EOF
# Create IngressRoute with dynamic hostname
cat <<EOF | kubectl -n traefik-system apply -f -
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
name: dashboard
spec:
entryPoints:
- web
- websecure
routes:
- match: Host(\`traefik.$DEVBOX_HOSTNAME\`)
kind: Rule
services:
- name: api@internal
kind: TraefikService
tls:
secretName: traefik-tls
EOF