diff --git a/tasks/main.yml b/tasks/main.yml index 1e1d118..859a484 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -7,7 +7,7 @@ k8s: state: present context: "{{ my_context }}" - name: tools + name: traefik api_version: v1 kind: Namespace @@ -20,7 +20,7 @@ kind: Secret metadata: name: basic-auth - namespace: tools + namespace: traefik type: Opaque data: basic_auth: "{{ basic_auth_data | b64encode }}" @@ -28,22 +28,39 @@ - basic_auth == true tags: traefik + - name: Add host label for traefik deployment + k8s: + state: present + context: "{{ my_context }}" + definition: + apiVersion: v1 + kind: Node + metadata: + name: "{{ item }}" + labels: + entrypoint: traefik + with_items: + - '{{ traefik_node_selector }}' + when: + - traefik_node_selector is defined + tags: traefik + - name: Get Deployment information object k8s_facts: context: "{{ my_context }}" api_version: v1 kind: Deployment name: traefik - namespace: tools + namespace: traefik field_selectors: - spec.template.spec.containers.image register: traefik_actual_resources - name: Retreive actual traefik version - shell: echo "{{ traefik_actual_resources.resources }}" | sed "s/.*traefik:v\([.0-9]*\).*/\1/" | uniq + shell: echo "{{ traefik_actual_resources.resources }}" | sed "s/.*traefik:\([.0-9]*\).*/\1/" | uniq register: traefik_actual_version - name: install / uninstall version 2.0 include_tasks: "version_2.0.yml" when: - - traefik_version == 2.0 or traefik_actual_version.stdout == 2.0 + - traefik_version == "2.0" or traefik_actual_version.stdout == "2.0" diff --git a/tasks/main.yml.old b/tasks/main.yml.old new file mode 100644 index 0000000..1e1d118 --- /dev/null +++ b/tasks/main.yml.old @@ -0,0 +1,49 @@ +#- debug: var=my_context +# tags: traefik + +- name: traefik setup + block: + - name: namespace + k8s: + state: present + context: "{{ my_context }}" + name: tools + api_version: v1 + kind: Namespace + + - name: Create a Secret object for basic authentification + k8s: + state: present + context: "{{ my_context }}" + definition: + apiVersion: v1 + kind: Secret + metadata: + name: basic-auth + namespace: tools + type: Opaque + data: + basic_auth: "{{ basic_auth_data | b64encode }}" + when: + - basic_auth == true + tags: traefik + + - name: Get Deployment information object + k8s_facts: + context: "{{ my_context }}" + api_version: v1 + kind: Deployment + name: traefik + namespace: tools + field_selectors: + - spec.template.spec.containers.image + register: traefik_actual_resources + + - name: Retreive actual traefik version + shell: echo "{{ traefik_actual_resources.resources }}" | sed "s/.*traefik:v\([.0-9]*\).*/\1/" | uniq + register: traefik_actual_version + + - name: install / uninstall version 2.0 + include_tasks: "version_2.0.yml" + when: + - traefik_version == 2.0 or traefik_actual_version.stdout == 2.0 diff --git a/tasks/version_2.0.yml b/tasks/version_2.0.yml index 9ba5e12..b251ba9 100644 --- a/tasks/version_2.0.yml +++ b/tasks/version_2.0.yml @@ -9,7 +9,7 @@ when: - traefik_version != "2.0" -- name: traefik files +- name: traefik files version {{ traefik_version }} need to be {{ traefik_2_0_state }} k8s: state: "{{ traefik_2_0_state }}" context: "{{ my_context }}" diff --git a/templates/2.0/traefik-clusterrolebinding.yml.j2 b/templates/2.0/traefik-clusterrolebinding.yml.j2 index 4719e69..9f58700 100644 --- a/templates/2.0/traefik-clusterrolebinding.yml.j2 +++ b/templates/2.0/traefik-clusterrolebinding.yml.j2 @@ -10,4 +10,4 @@ roleRef: subjects: - kind: ServiceAccount name: traefik-ingress-controller - namespace: tools + namespace: traefik diff --git a/templates/2.0/traefik-cm.yml.j2 b/templates/2.0/traefik-cm.yml.j2 index ade2719..c0476da 100644 --- a/templates/2.0/traefik-cm.yml.j2 +++ b/templates/2.0/traefik-cm.yml.j2 @@ -45,4 +45,4 @@ metadata: labels: app: traefik name: traefik - namespace: tools + namespace: traefik diff --git a/templates/2.0/traefik-crd-ingressroute.yml.j2 b/templates/2.0/traefik-crd-ingressroute.yml.j2 index 4e83639..41f70f9 100644 --- a/templates/2.0/traefik-crd-ingressroute.yml.j2 +++ b/templates/2.0/traefik-crd-ingressroute.yml.j2 @@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1beta1 kind: CustomResourceDefinition metadata: name: ingressroutes.traefik.containo.us - namespace: tools + namespace: traefik labels: app: traefik diff --git a/templates/2.0/traefik-crd-ingressroutetcp.yml.j2 b/templates/2.0/traefik-crd-ingressroutetcp.yml.j2 index 3900786..107c4e5 100644 --- a/templates/2.0/traefik-crd-ingressroutetcp.yml.j2 +++ b/templates/2.0/traefik-crd-ingressroutetcp.yml.j2 @@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1beta1 kind: CustomResourceDefinition metadata: name: ingressroutetcps.traefik.containo.us - namespace: tools + namespace: traefik labels: app: traefik diff --git a/templates/2.0/traefik-crd-middleware.yml.j2 b/templates/2.0/traefik-crd-middleware.yml.j2 index 0a0cf65..b517ac8 100644 --- a/templates/2.0/traefik-crd-middleware.yml.j2 +++ b/templates/2.0/traefik-crd-middleware.yml.j2 @@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1beta1 kind: CustomResourceDefinition metadata: name: middlewares.traefik.containo.us - namespace: tools + namespace: traefik labels: app: traefik diff --git a/templates/2.0/traefik-dashboard-insecure.yml.j2 b/templates/2.0/traefik-dashboard-insecure.yml.j2 index 98293d6..f3b1386 100644 --- a/templates/2.0/traefik-dashboard-insecure.yml.j2 +++ b/templates/2.0/traefik-dashboard-insecure.yml.j2 @@ -2,7 +2,7 @@ apiVersion: traefik.containo.us/v1alpha1 kind: IngressRoute metadata: name: traefik-dashboard-insecure - namespace: tools + namespace: traefik labels: app: traefik diff --git a/templates/2.0/traefik-dashboard-svc.yml.j2 b/templates/2.0/traefik-dashboard-svc.yml.j2 index efef8b5..2091a13 100644 --- a/templates/2.0/traefik-dashboard-svc.yml.j2 +++ b/templates/2.0/traefik-dashboard-svc.yml.j2 @@ -4,7 +4,7 @@ metadata: labels: app: traefik name: traefik-dashboard - namespace: tools + namespace: traefik spec: ports: diff --git a/templates/2.0/traefik-dashboard.yml.j2 b/templates/2.0/traefik-dashboard.yml.j2 index a08b11e..085db70 100644 --- a/templates/2.0/traefik-dashboard.yml.j2 +++ b/templates/2.0/traefik-dashboard.yml.j2 @@ -2,7 +2,7 @@ apiVersion: traefik.containo.us/v1alpha1 kind: IngressRoute metadata: name: traefik-dashboard - namespace: tools + namespace: traefik labels: app: traefik diff --git a/templates/2.0/traefik-dp.yml.j2 b/templates/2.0/traefik-dp.yml.j2 index 1a64b11..5214740 100644 --- a/templates/2.0/traefik-dp.yml.j2 +++ b/templates/2.0/traefik-dp.yml.j2 @@ -1,13 +1,13 @@ kind: Deployment apiVersion: apps/v1 metadata: - namespace: tools + namespace: traefik name: traefik labels: app: traefik spec: - replicas: 1 + replicas: {% if traefik_node_selector is defined %}{{ traefik_node_selector|length }}{% else %}1{% endif %} selector: matchLabels: app: traefik @@ -27,15 +27,15 @@ spec: - name: http containerPort: 80 protocol: TCP -# hostPort: 80 + hostPort: 80 - name: https containerPort: 443 protocol: TCP -# hostPort: 443 + hostPort: 443 - name: traefik containerPort: 8080 protocol: TCP -# hostPort: 8080 + hostPort: 8080 readinessProbe: httpGet: path: /ping @@ -66,7 +66,7 @@ spec: name: config {% if traefik_node_selector is defined %} nodeSelector: - kubernetes.io/hostname: "{% for node_selector in traefik_node_selector %}{{ node_selector }}{% if not loop.last %}, {% endif %}{% endfor %}" + entrypoint: traefik {% endif %} dnsPolicy: ClusterFirst hostNetwork: false diff --git a/templates/2.0/traefik-middleware-basicauth.yml.j2 b/templates/2.0/traefik-middleware-basicauth.yml.j2 index b3701d4..2b3ff9f 100644 --- a/templates/2.0/traefik-middleware-basicauth.yml.j2 +++ b/templates/2.0/traefik-middleware-basicauth.yml.j2 @@ -2,6 +2,7 @@ apiVersion: traefik.containo.us/v1alpha1 kind: Middleware metadata: name: basic-auth + namespace: traefik spec: basicAuth: secret: basic-auth \ No newline at end of file diff --git a/templates/2.0/traefik-middleware-httpsredirect.yml.j2 b/templates/2.0/traefik-middleware-httpsredirect.yml.j2 index 07af55a..812c1a4 100644 --- a/templates/2.0/traefik-middleware-httpsredirect.yml.j2 +++ b/templates/2.0/traefik-middleware-httpsredirect.yml.j2 @@ -2,6 +2,7 @@ apiVersion: traefik.containo.us/v1alpha1 kind: Middleware metadata: name: https-only + namespace: traefik spec: redirectScheme: scheme: https \ No newline at end of file diff --git a/templates/2.0/traefik-sa.yml.j2 b/templates/2.0/traefik-sa.yml.j2 index 7ca4339..16505c8 100644 --- a/templates/2.0/traefik-sa.yml.j2 +++ b/templates/2.0/traefik-sa.yml.j2 @@ -1,5 +1,5 @@ apiVersion: v1 kind: ServiceAccount metadata: - namespace: tools + namespace: traefik name: traefik-ingress-controller diff --git a/templates/2.0/traefik-svc.yml.j2 b/templates/2.0/traefik-svc.yml.j2 index b2306bd..afff84c 100644 --- a/templates/2.0/traefik-svc.yml.j2 +++ b/templates/2.0/traefik-svc.yml.j2 @@ -4,7 +4,7 @@ metadata: labels: app: traefik name: traefik - namespace: tools + namespace: traefik spec: ports: