<p>Should I deploy traefik 1.7.x as DaemonSet or as A deployment in GKE (Google K8S)?</p>
<h3>Environment Description</h3>
<p>Kubernetes clusters with node autoscaler in Google cloud, hosting several production clusters.
Clusters can extend up to 90 nodes (minimum is 6 nodes), currently we have <code>traefik</code> pod deployed with 10 replicas in each cluster (we use kustomize to deploy the same manifests in all clusters).</p>
<p>We notice slow response time in the cluster that has 18 nodes (<code>europe-west1</code> region), compared to our cluster in <code>australia-southeast1</code> region, which has 6 nodes. Both clusters has 10 replicas of traefik.</p>
<h3>Deployment Specs</h3>
<p>traefik.toml:</p>
<pre><code>    [kubernetes]
    # all namespaces!
    namespaces = []
</code></pre>
<p>Service.yaml</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  labels:
    app: traefik
  name: traefik-ingress
  namespace: ingress-traefik
spec:
  externalTrafficPolicy: Local
  ports:
  - name: http
    port: 80
    protocol: TCP
    targetPort: 80
  - name: https
    port: 443
    protocol: TCP
    targetPort: 443
  selector:
    app: traefik
  sessionAffinity: None
  type: LoadBalancer
  loadBalancerIP: {{LOAD_BALANCER_IP}}
</code></pre>
<p>Deployment.yaml</p>
<pre><code>---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: traefik
  name: traefik
  namespace: ingress-traefik
spec:
  replicas: 10
  selector:
    matchLabels:
      app: traefik

  template:
    metadata:
      labels:
        app: traefik
    spec:
      containers:
      - args:
        - --configfile=/config/traefik.toml
        image: traefik:1.7.9-alpine
</code></pre>
<h3>Questions</h3>
<ol>
<li>In this scenario (using GKE node autoscaler) what would be the optimal configuration for our clusters? Using Deployment or a DaemonSet for traefik?</li>
<li>Does the amount of traefik pods has effect on response time according to the cluster size (node count)?</li>
<li>Does routing inside the cluster (hops between pod, service and nodes networks) is easier for traefik when using a DaemonSet (pod for each node) or by using a deployment of several replicas for the whole cluster? (We use K8S namespaces for each of our https service and traefik has its own namespace).</li>
</ol>

<h2>Deploy Traefik using a Deployment or DaemonSet?</h2>
<p>It is possible to use Traefik with a <a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment" rel="nofollow noreferrer">Deployment</a> or a <a href="https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/" rel="nofollow noreferrer">DaemonSet</a> object, whereas both options have their own pros and cons:</p>
<ul>
<li><p>The scalability can be much better when using a Deployment, because you will have a Single-Pod-per-Node model when using a DaemonSet, whereas you may need less replicas based on your environment when using a Deployment.</p>
</li>
<li><p>DaemonSets automatically scale to new nodes, when the nodes join the cluster, whereas Deployment pods are only scheduled on new nodes if required.</p>
</li>
<li><p>DaemonSets ensure that only one replica of pods run on any single node. Deployments require affinity settings if you want to ensure that two pods don't end up on the same node.</p>
</li>
<li><p>DaemonSets can be run with the NET_BIND_SERVICE capability, which will allow it to bind to port 80/443/etc on each host. This will allow bypassing the kube-proxy, and reduce traffic hops. Note that this is against the Kubernetes Best Practices <a href="https://kubernetes.io/docs/concepts/configuration/overview/#services" rel="nofollow noreferrer">Guidelines</a> , and raises the potential for scheduling/scaling issues. Despite potential issues, this remains the choice for most ingress controllers.</p>
</li>
</ul>
<h3>There are some significant differences between using Deployments and DaemonSets:</h3>
<ul>
<li><p>The Deployment has easier up and down scaling possibilities. It can implement full pod lifecycle and supports rolling updates from Kubernetes 1.2. At least one Pod is needed to run the Deployment.</p>
</li>
<li><p>The DaemonSet automatically scales to all nodes that meets a specific selector and guarantees to fill nodes one at a time. Rolling updates are fully supported from Kubernetes 1.7 for DaemonSets as well.</p>
</li>
</ul>
<p>You might want to have a look at additional <a href="https://doc.traefik.io/traefik/" rel="nofollow noreferrer">traefik docs</a></p>
