<p>Inspired by <a href="https://www.kubetools.io/kubernetes/using-traefik-v2-as-a-reverse-proxy-for-kubernetes-a-step-by-step-guide-for-developers-and-kubernetes-enthusiasts/" rel="nofollow noreferrer">this nice article</a> I tried to setup a very basic Traefik environment on Kubernetes. I know this is the minimum setup without security, etc. We use Traefik for many years on Docker Swarm and want to move on to Kubernetes.</p>
<p>In short: this is the basic traefik yml file with deployment, service and ingressroute:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: traefik
spec:
  selector:
    matchLabels:
      app: traefik
  replicas: 1
  template:
    metadata:
      labels:
        app: traefik
    spec:
      containers:
      - name: traefik
        image: traefik:v2.5
        ports:
        - name: http
          containerPort: 80
        - name: admin
          containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: traefik
spec:
  selector:
    app: traefik
  ports:
  - name: http
    port: 80
    protocol: TCP
    targetPort: http
  - name: admin
    port: 8080
    protocol: TCP
    targetPort: admin
  type: NodePort
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: traefik-web-ui
spec:
  entryPoints:
    - web
  routes:
  - match: PathPrefix(`/dashboard`)
    kind: Rule
    services:
    - name: traefik
      port: 8080
</code></pre>
<p>The NgInx yaml is:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 1
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - name: http
          containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginx
spec:
  selector:
    app: nginx
  ports:
  - name: http
    port: 80
    protocol: TCP
    targetPort: http
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: nginx
spec:
  entryPoints:
    - web
  routes:
  - match: PathPrefix(`/nginx`)
    kind: Rule
    services:
    - name: nginx
      port: http
</code></pre>
<p>Applying I do with:</p>
<pre><code>$ kubectl apply -f traefik.yaml
$ kubectl apply -f nginx.yaml
</code></pre>
<p>All is running:</p>
<p><a href="https://i.stack.imgur.com/D3ELn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/D3ELn.png" alt="enter image description here" /></a></p>
<p><a href="https://i.stack.imgur.com/1gdA5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1gdA5.png" alt="enter image description here" /></a></p>
<p>Browsing to either http://localhost/dashboard, http://localhost/dashboard/, http://localhost/nginx or http://localhost/nginx/  gives no result but ERR_CONNECTION_REFUSED.</p>

tm1701
<p>I would drop this method of deploying Traefik.</p>
<p>The official way is much more easier to deploy and manage:</p>
<ol>
<li>Install the helm chart</li>
</ol>
<pre class="lang-bash prettyprint-override"><code>helm repo add traefik https://traefik.github.io/charts
helm repo update
helm install traefik traefik/traefik
</code></pre>
<ol start="2">
<li>Expose the dashboard</li>
</ol>
<pre class="lang-bash prettyprint-override"><code>kubectl port-forward $(kubectl get pods --selector &quot;app.kubernetes.io/name=traefik&quot; --output=name) 9000:9000
</code></pre>
<ol start="3">
<li>Access on <a href="http://127.0.0.1:9000/dashboard/" rel="nofollow noreferrer">http://127.0.0.1:9000/dashboard/</a></li>
</ol>
