Skip to content

Instantly share code, notes, and snippets.

@gintsgints
Last active February 19, 2020 18:41
Show Gist options
  • Save gintsgints/577348ea2d39ded09cb32969cdb42c64 to your computer and use it in GitHub Desktop.
Save gintsgints/577348ea2d39ded09cb32969cdb42c64 to your computer and use it in GitHub Desktop.

Traefik install instructions

Based on this - https://patrick.easte.rs/post/traefik-tls-k8s/ And this - https://docs.traefik.io/v1.7/user-guide/kubernetes/

Create secret for keys

kubectl create secret generic traefik-cert --from-file=yourcert.crt --from-file=yourkey.key

Store traefik config

kubectl create configmap traefik-conf --from-file=traefik.toml
# traefik.toml
defaultEntryPoints = ["http","https"]

[entryPoints]
  [entryPoints.http]
    address = ":80"
    [entryPoints.http.redirect]
        entryPoint = "https"
        regex = "^http://localhost/(.*)"
        replacement = "http://mydomain/$1"
        permanent = true

  [entryPoints.https]
    address = ":443"
    [entryPoints.https.tls]
      [[entryPoints.https.tls.certificates]]
      certFile = "/ssl/yourcert.crt"
      keyFile = "/ssl/yourcert.key"

traefik-ds.yaml

---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: traefik-ingress-controller
  namespace: kube-system
---
kind: DaemonSet
apiVersion: apps/v1
metadata:
  name: traefik-ingress-controller
  namespace: kube-system
  labels:
    k8s-app: traefik-ingress-lb
spec:
  selector:
    matchLabels:
      k8s-app: traefik-ingress-lb
      name: traefik-ingress-lb
  template:
    metadata:
      labels:
        k8s-app: traefik-ingress-lb
        name: traefik-ingress-lb
    spec:
      serviceAccountName: traefik-ingress-controller
      terminationGracePeriodSeconds: 60
      volumes:
      - name: ssl
        secret:
          secretName: traefik-cert
      - name: config
        configMap:
          name: traefik-conf
      containers:
      - image: traefik:v1.7
        name: traefik-ingress-lb
        volumeMounts:
        - mountPath: "/ssl"
          name: "ssl"
        - mountPath: "/config"
          name: "config"
        ports:
        - name: http
          containerPort: 80
          hostPort: 80
        - name: https
          containerPort: 443
          hostPort: 443
        - name: admin
          containerPort: 8080
          hostPort: 8080
        securityContext:
          capabilities:
            drop:
            - ALL
            add:
            - NET_BIND_SERVICE
        args:
        - --api
        - --kubernetes
        - --logLevel=INFO
        - --configfile=/config/traefik.toml
---
kind: Service
apiVersion: v1
metadata:
  name: traefik-ingress-service
  namespace: kube-system
spec:
  selector:
    k8s-app: traefik-ingress-lb
  ports:
    - protocol: TCP
      port: 80
      name: web
    - protocol: TCP
      port: 443
      name: https
    - protocol: TCP
      port: 8080
      name: admin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment