Help

Vars editor

Variables in articles are noted {{myVar}}

Legend

A link to a page of this blog
A link to a section of this page
A link to a template of this guide. Templates are files in which you should replace your variables
A variable
A link to an external tool documentation
This page looks best with JavaScript enabled

Setup the cluster's internal router

 ·  via commit 1c91ff1 (chore: change shortcodes format (HTML tag like)) by Gerkin  ·  โ˜• 8 min read
What's on this Page

Start by creating traefik required resources. You can directly use resources from the  kubernetes/traefik templates: it does not contain variables. Those are taken from  traefik docs mixed up with  this PR for kubernetes 1.19 support and schemas.

Please look forward for  this issue in traefik about official v1.19 support.

1
2
3
4
5
# File: ./kubernetes/traefik/01-Namespace.yaml
apiVersion: v1
kind: Namespace
metadata:
  name: traefik
  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
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
# File: ./kubernetes/traefik/02-CustomResourcesDefinitions.yaml
# From https://doc.traefik.io/traefik/v2.4/user-guides/crd-acme/#ingressroute-definition
# Applying schemas from https://github.com/traefik/traefik-helm-chart/pull/157/files

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: ingressroutes.traefik.containo.us

spec:
  group: traefik.containo.us
  versions:
    - name: v1alpha1
      served: true
      storage: true
      schema:
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              properties:
                routes:
                  type: array
                  items:
                    type: object
                    properties:
                      match:
                        type: string
                      kind:
                        type: string
                      priority:
                        type: integer
                      services:
                        type: array
                        items:
                          type: object
                          properties:
                            sticky:
                              type: object
                              properties:
                                cookie:
                                  type: object
                                  properties:
                                    name:
                                      type: string
                                    secure:
                                      type: boolean
                                    httpOnly:
                                      type: boolean
                            namespace:
                              type: string
                            kind:
                              type: string
                            name:
                              type: string
                            weight:
                              type: integer
                            responseForwarding:
                              type: object
                              properties:
                                flushInterval:
                                  type: string
                            passHostHeader:
                              type: boolean
                            healthCheck:
                              type: object
                              properties:
                                path:
                                  type: string
                                host:
                                  type: string
                                scheme:
                                  type: string
                                intervalSeconds:
                                  type: integer
                                timeoutSeconds:
                                  type: integer
                                headers:
                                  type: object
                            strategy:
                              type: string
                            scheme:
                              type: string
                            port:
                              type: integer
                      middlewares:
                        type: array
                        items:
                          type: object
                          properties:
                            name:
                              type: string
                            namespace:
                              type: string
                          required:
                            - name
                            - namespace
                entryPoints:
                  type: array
                  items:
                    type: string
                tls:
                  type: object
                  properties:
                    secretName:
                      type: string
                    options:
                      type: object
                      properties:
                        name:
                          type: string
                        namespace:
                          type: string
                    store:
                      type: object
                      properties:
                        name:
                          type: string
                        namespace:
                          type: string
                    certResolver:
                      type: string
                    domains:
                      type: array
                      items:
                        type: object
                        properties:
                          main:
                            type: string
                          sans:
                            type: array
                            items:
                              type: string
  names:
    kind: IngressRoute
    plural: ingressroutes
    singular: ingressroute
  scope: Namespaced

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: middlewares.traefik.containo.us

spec:
  group: traefik.containo.us
  versions:
    - name: v1alpha1
      served: true
      storage: true
      schema:
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              properties:
                addPrefix:
                  type: object
                  properties:
                    prefix:
                      type: string
                stripPrefix:
                  type: object
                  properties:
                    prefixes:
                      type: array
                      items:
                        type: string
                    forceSlash:
                      type: boolean
                stripPrefixRegex:
                  type: object
                  properties:
                    regex:
                      type: array
                      items:
                        type: string
                replacePath:
                  type: object
                  properties:
                    path:
                      type: string
                replacePathRegex:
                  type: object
                  properties:
                    regex:
                      type: string
                    replacement:
                      type: string
                chain:
                  type: object
                  properties:
                    middlewares:
                      type: array
                      items:
                        type: object
                        properties:
                          name:
                            type: string
                          namespace:
                            type: string
                        required:
                          - name
                          - namespace
                ipWhiteList:
                  type: object
                  properties:
                    sourceRange:
                      type: array
                      items:
                        type: string
                    ipStrategy:
                      type: object
                      properties:
                        depth:
                          type: integer
                        excludedIPs:
                          type: array
                          items:
                            type: string
                headers:
                  type: object
                  properties:
                    customRequestHeaders:
                      type: object
                    customResponseHeaders:
                      type: object
                    accessControlAllowCredentials:
                      type: boolean
                    accessControlAllowHeaders:
                      type: array
                      items:
                        type: string
                    accessControlAllowMethods:
                      type: array
                      items:
                        type: string
                    accessControlAllowOrigin:
                      type: string
                    accessControlAllowOriginList:
                      type: array
                      items:
                        type: string
                    accessControlExposeHeaders:
                      type: array
                      items:
                        type: string
                    accessControlMaxAge:
                      type: integer
                    addVaryHeader:
                      type: boolean
                    allowedHosts:
                      type: array
                      items:
                        type: string
                    hostsProxyHeaders:
                      type: array
                      items:
                        type: string
                    sslRedirect:
                      type: boolean
                    sslTemporaryRedirect:
                      type: boolean
                    sslHost:
                      type: string
                    sslProxyHeaders:
                      type: object
                    sslForceHost:
                      type: boolean
                    stsSeconds:
                      type: integer
                    stsIncludeSubdomains:
                      type: boolean
                    stsPreload:
                      type: boolean
                    forceSTSheader:
                      type: boolean
                    frameDeny:
                      type: boolean
                    customFrameOptionsValue:
                      type: string
                    contentTypeNosniff:
                      type: boolean
                    browserXssFilter:
                      type: boolean
                    customBrowserXSSValue:
                      type: string
                    contentSecurityPolicy:
                      type: string
                    publicKey:
                      type: string
                    referrerPolicy:
                      type: string
                    featurePolicy:
                      type: string
                    isDevelopment:
                      type: boolean
                errors:
                  type: object
                  properties:
                    status:
                      type: array
                      items:
                        type: string
                    service:
                      type: object
                      properties:
                        sticky:
                          type: object
                          properties:
                            cookie:
                              type: object
                              properties:
                                name:
                                  type: string
                                secure:
                                  type: boolean
                                httpOnly:
                                  type: boolean
                        namespace:
                          type: string
                        kind:
                          type: string
                        name:
                          type: string
                        weight:
                          type: integer
                        responseForwarding:
                          type: object
                          properties:
                            flushInterval:
                              type: string
                        passHostHeader:
                          type: boolean
                        healthCheck:
                          type: object
                          properties:
                            path:
                              type: string
                            host:
                              type: string
                            scheme:
                              type: string
                            intervalSeconds:
                              type: integer
                            timeoutSeconds:
                              type: integer
                            headers:
                              type: object
                        strategy:
                          type: string
                        scheme:
                          type: string
                        port:
                          type: integer
                    query:
                      type: string
                rateLimit:
                  type: object
                  properties:
                    average:
                      type: integer
                    burst:
                      type: integer
                    sourceCriterion:
                      type: object
                      properties:
                        ipStrategy:
                          type: object
                          properties:
                            depth:
                              type: integer
                            excludedIPs:
                              type: array
                              items:
                                type: string
                        requestHeaderName:
                          type: string
                        requestHost:
                          type: boolean
                redirectRegex:
                  type: object
                  properties:
                    regex:
                      type: string
                    replacement:
                      type: string
                    permanent:
                      type: boolean
                redirectScheme:
                  type: object
                  properties:
                    scheme:
                      type: string
                    port:
                      type: string
                    permanent:
                      type: boolean
                basicAuth:
                  type: object
                  properties:
                    secret:
                      type: string
                    realm:
                      type: string
                    removeHeader:
                      type: boolean
                    headerField:
                      type: string
                digestAuth:
                  type: object
                  properties:
                    secret:
                      type: string
                    removeHeader:
                      type: boolean
                    realm:
                      type: string
                    headerField:
                      type: string
                forwardAuth:
                  type: object
                  properties:
                    address:
                      type: string
                    trustForwardHeader:
                      type: boolean
                    authResponseHeaders:
                      type: array
                      items:
                        type: string
                    tls:
                      type: object
                      properties:
                        caSecret:
                          type: string
                        caOptional:
                          type: boolean
                        certSecret:
                          type: string
                        insecureSkipVerify:
                          type: boolean
                inFlightReq:
                  type: object
                  properties:
                    amount:
                      type: integer
                    sourceCriterion:
                      type: object
                      properties:
                        ipStrategy:
                          type: object
                          properties:
                            depth:
                              type: integer
                            excludedIPs:
                              type: array
                              items:
                                type: string
                        requestHeaderName:
                          type: string
                        requestHost:
                          type: boolean
                buffering:
                  type: object
                  properties:
                    maxRequestBodyBytes:
                      type: integer
                    memRequestBodyBytes:
                      type: integer
                    maxResponseBodyBytes:
                      type: integer
                    memResponseBodyBytes:
                      type: integer
                    retryExpression:
                      type: string
                circuitBreaker:
                  type: object
                  properties:
                    expression:
                      type: string
                compress:
                  type: object
                  properties:
                    excludedContentTypes:
                      type: array
                      items:
                        type: string
                passTLSClientCert:
                  type: object
                  properties:
                    pem:
                      type: boolean
                    info:
                      type: object
                      properties:
                        notAfter:
                          type: boolean
                        notBefore:
                          type: boolean
                        sans:
                          type: boolean
                        subject:
                          type: object
                          properties:
                            country:
                              type: boolean
                            province:
                              type: boolean
                            locality:
                              type: boolean
                            organization:
                              type: boolean
                            commonName:
                              type: boolean
                            serialNumber:
                              type: boolean
                            domainComponent:
                              type: boolean
                        issuer:
                          type: object
                          properties:
                            country:
                              type: boolean
                            province:
                              type: boolean
                            locality:
                              type: boolean
                            organization:
                              type: boolean
                            commonName:
                              type: boolean
                            serialNumber:
                              type: boolean
                            domainComponent:
                              type: boolean
                        serialNumber:
                          type: boolean
                retry:
                  type: object
                  properties:
                    attempts:
                      type: integer
                contentType:
                  type: object
                  properties:
                    autoDetect:
                      type: boolean
  names:
    kind: Middleware
    plural: middlewares
    singular: middleware
  scope: Namespaced

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: ingressroutetcps.traefik.containo.us

spec:
  group: traefik.containo.us
  versions:
    - name: v1alpha1
      served: true
      storage: true
      schema:
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              properties:
                routes:
                  type: array
                  items:
                    type: object
                    properties:
                      match:
                        type: string
                      services:
                        type: array
                        items:
                          type: object
                          properties:
                            name:
                              type: string
                            namespace:
                              type: string
                            port:
                              type: integer
                            weight:
                              type: integer
                            terminationDelay:
                              type: integer
                entryPoints:
                  type: array
                  items:
                    type: string
                tls:
                  type: object
                  properties:
                    secretName:
                      type: string
                    passthrough:
                      type: boolean
                    options:
                      type: object
                      properties:
                        name:
                          type: string
                        namespace:
                          type: string
                    store:
                      type: object
                      properties:
                        name:
                          type: string
                        namespace:
                          type: string
                    certResolver:
                      type: string
                    domains:
                      type: array
                      items:
                        type: object
                        properties:
                          main:
                            type: string
                          sans:
                            type: array
                            items:
                              type: string
  names:
    kind: IngressRouteTCP
    plural: ingressroutetcps
    singular: ingressroutetcp
  scope: Namespaced

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: ingressrouteudps.traefik.containo.us

spec:
  group: traefik.containo.us
  versions:
  - name: v1alpha1
    served: true
    storage: true
  names:
    kind: IngressRouteUDP
    plural: ingressrouteudps
    singular: ingressrouteudp
  scope: Namespaced

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: tlsoptions.traefik.containo.us

spec:
  group: traefik.containo.us
  versions:
    - name: v1alpha1
      served: true
      storage: true
      schema:
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              properties:
                minVersion:
                  type: string
                maxVersion:
                  type: string
                cipherSuites:
                  type: array
                  items:
                    type: string
                curvePreferences:
                  type: array
                  items:
                    type: string
                clientAuth:
                  type: object
                  properties:
                    secretNames:
                      type: array
                      items:
                        type: string
                    clientAuthType:
                      type: string
                      enum:
                        - NoClientCert
                        - RequestClientCert
                        - VerifyClientCertIfGiven
                        - RequireAndVerifyClientCert
                sniStrict:
                  type: boolean
                preferServerCipherSuites:
                  type: boolean
  names:
    kind: TLSOption
    plural: tlsoptions
    singular: tlsoption
  scope: Namespaced

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: tlsstores.traefik.containo.us

spec:
  group: traefik.containo.us
  versions:
  - name: v1alpha1
    served: true
    storage: true
  names:
    kind: TLSStore
    plural: tlsstores
    singular: tlsstore
  scope: Namespaced

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: traefikservices.traefik.containo.us

spec:
  group: traefik.containo.us
  versions:
    - name: v1alpha1
      served: true
      storage: true
      schema:
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              properties:
                weighted:
                  type: object
                  properties:
                    services:
                      type: array
                      items:
                        type: object
                        properties:
                          sticky:
                            type: object
                            properties:
                              cookie:
                                type: object
                                properties:
                                  name:
                                    type: string
                                  secure:
                                    type: boolean
                                  httpOnly:
                                    type: boolean
                          namespace:
                            type: string
                          kind:
                            type: string
                          name:
                            type: string
                          weight:
                            type: integer
                          responseForwarding:
                            type: object
                            properties:
                              flushInterval:
                                type: string
                          passHostHeader:
                            type: boolean
                          healthCheck:
                            type: object
                            properties:
                              path:
                                type: string
                              host:
                                type: string
                              scheme:
                                type: string
                              intervalSeconds:
                                type: integer
                              timeoutSeconds:
                                type: integer
                              headers:
                                type: object
                          strategy:
                            type: string
                          scheme:
                            type: string
                          port:
                            type: integer
                    sticky:
                      type: object
                      properties:
                        cookie:
                          type: object
                          properties:
                            name:
                              type: string
                            secure:
                              type: boolean
                            httpOnly:
                              type: boolean
                mirroring:
                  type: object
                  properties:
                    weight:
                      type: integer
                    responseForwarding:
                      type: object
                      properties:
                        flushInterval:
                          type: string
                    passHostHeader:
                      type: boolean
                    healthCheck:
                      type: object
                      properties:
                        path:
                          type: string
                        host:
                          type: string
                        scheme:
                          type: string
                        intervalSeconds:
                          type: integer
                        timeoutSeconds:
                          type: integer
                        headers:
                          type: object
                    strategy:
                      type: string
                    scheme:
                      type: string
                    port:
                      type: integer
                    sticky:
                      type: object
                      properties:
                        cookie:
                          type: object
                          properties:
                            name:
                              type: string
                            secure:
                              type: boolean
                            httpOnly:
                              type: boolean
                    namespace:
                      type: string
                    kind:
                      type: string
                    name:
                      type: string
                    mirrors:
                      type: array
                      items:
                        type: object
                        properties:
                          name:
                            type: string
                          kind:
                            type: string
                          namespace:
                            type: string
                          sticky:
                            type: object
                            properties:
                              cookie:
                                type: object
                                properties:
                                  name:
                                    type: string
                                  secure:
                                    type: boolean
                                  httpOnly:
                                    type: boolean
                          port:
                            type: integer
                          scheme:
                            type: string
                          strategy:
                            type: string
                          healthCheck:
                            type: object
                            properties:
                              path:
                                type: string
                              host:
                                type: string
                              scheme:
                                type: string
                              intervalSeconds:
                                type: integer
                              timeoutSeconds:
                                type: integer
                              headers:
                                type: object
                          passHostHeader:
                            type: boolean
                          responseForwarding:
                            type: object
                            properties:
                              flushInterval:
                                type: string
                          weight:
                            type: integer
                          percent:
                            type: integer
  names:
    kind: TraefikService
    plural: traefikservices
    singular: traefikservice
  scope: Namespaced

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: serverstransports.traefik.containo.us

spec:
  group: traefik.containo.us
  versions:
  - name: v1alpha1
    served: true
    storage: true
  names:
    kind: ServersTransport
    plural: serverstransports
    singular: serverstransport
  scope: Namespaced
 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
65
66
67
68
69
70
71
72
73
74
# File: ./kubernetes/traefik/03-Rbac.yaml
# Oddly, those definitions are in the CRD, but are not CRDs
# https://doc.traefik.io/traefik/v2.4/user-guides/crd-acme/#ingressroute-definition

apiVersion: v1
kind: ServiceAccount
metadata:
  name: traefik
  namespace: traefik

---

kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: traefik

rules:
  - apiGroups:
      - ""
    resources:
      - services
      - endpoints
      - secrets
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - extensions
      - networking.k8s.io
    resources:
      - ingresses
      - ingressclasses
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - extensions
    resources:
      - ingresses/status
    verbs:
      - update
  - apiGroups:
      - traefik.containo.us
    resources:
      - middlewares
      - ingressroutes
      - traefikservices
      - ingressroutetcps
      - ingressrouteudps
      - tlsoptions
      - tlsstores
      - serverstransports
    verbs:
      - get
      - list
      - watch

---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: traefik

roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: traefik
subjects:
  - kind: ServiceAccount
    name: traefik
    namespace: traefik
 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
# File: ./kubernetes/traefik/04-IngressController.yaml
# https://doc.traefik.io/traefik/v2.4/user-guides/crd-acme/#deployments
kind: Deployment
apiVersion: apps/v1
metadata:
  name: traefik
  namespace: traefik
  labels:
    app: traefik
    component: ingress-controller

spec:
  replicas: 1
  selector:
    matchLabels:
      app: traefik
      component: ingress-controller
  template:
    metadata:
      labels:
        app: traefik
        component: ingress-controller
    spec:
      serviceAccountName: traefik
      containers:
        - name: traefik
          image: traefik:v2.4
          args:
            - --api=false
            - --api.dashboard=false
            - --accesslog
            - --entrypoints.web.Address=:8000
            - --entrypoints.websecure.Address=:4443
            - --providers.kubernetescrd
            - --certificatesresolvers.myresolver.acme.tlschallenge
            - --certificatesresolvers.myresolver.acme.email=FILL@ME.COM
            - --certificatesresolvers.myresolver.acme.storage=acme.json
            # Please note that this is the staging Let's Encrypt server.
            # Once you get things working, you should remove that whole line altogether.
            - --certificatesresolvers.myresolver.acme.caserver=https://acme-staging-v02.api.letsencrypt.org/directory
          ports:
            - name: web
              containerPort: 8000
            - name: websecure
              containerPort: 4443
            - name: admin
              containerPort: 8080
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File: ./kubernetes/traefik/05-Services.yaml
# https://doc.traefik.io/traefik/v2.4/user-guides/crd-acme/#services
apiVersion: v1
kind: Service
metadata:
  name: traefik
  namespace: traefik

spec:
  ports:
    - protocol: TCP
      name: web
      port: 8000
    - protocol: TCP
      name: admin
      port: 8080
    - protocol: TCP
      name: websecure
      port: 4443
  selector:
    app: traefik
    component: ingress-controller
  type: LoadBalancer
1
2
3
4
5
kubectl apply -f ./kubernetes/traefik/01-Namespace.yaml
kubectl apply -f ./kubernetes/traefik/02-CustomResourcesDefinitions.yaml
kubectl apply -f ./kubernetes/traefik/03-Rbac.yaml
kubectl apply -f ./kubernetes/traefik/04-IngressController.yaml
kubectl apply -f ./kubernetes/traefik/05-Services.yaml

You can now use the  custom resource kind IngressRoute to map routes using traefik.

To check if everything works so far, you can use a test nginx instance from  kubernetes/xx-WhoAmI.yaml. Once deployed, you should be able to display the nginx default page by reaching https://test.{{cluster.baseHostName}} from your host.

 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
65
66
67
68
69
70
71
72
73
74
75
76
77
apiVersion: v1
kind: Namespace
metadata:
  name: whoami
---
kind: Deployment
apiVersion: apps/v1
metadata:
  name: whoami
  namespace: whoami
  labels:
    app: whoami
spec:
  replicas: 1
  selector:
    matchLabels:
      app: whoami
  template:
    metadata:
      labels:
        app: whoami
    spec:
      containers:
        - name: whoami
          image: traefik/whoami
          ports:
            - name: web
              containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: whoami
  namespace: whoami
spec:
  ports:
    - protocol: TCP
      name: web
      port: 80
  selector:
    app: whoami
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: ingress-tls
  namespace: whoami # Must be the same as the service
spec:
  entryPoints:
    - websecure
  routes:
  - match: Host(`whoami.{{cluster.baseHostName}}`) && PathPrefix(`/tls`)
    kind: Rule
    services:
    # Beware: the service MUST be in the same namespace than the IngressRoute.
    - name: whoami
      kind: Service
      port: 80
  tls:
    certResolver: myresolver
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: ingress-notls
  namespace: whoami # Must be the same as the service
spec:
  entryPoints:
    - web
  routes:
  - match: Host(`whoami.{{cluster.baseHostName}}`) && PathPrefix(`/notls`)
    kind: Rule
    services:
    # Beware: the service MUST be in the same namespace than the IngressRoute.
    - name: whoami
      kind: Service
      port: 80
1
2
kubectl apply -f ./kubernetes/xx-WhoAmI.yaml
curl -kH 'Host: whoami.{{cluster.baseHostName}}' "https://$(kubectl --namespace traefik get svc traefik -o json | jq --raw-output '.status.loadBalancer.ingress[].ip')"

Yes ! Our host can access traefik, that redirects the request to whoami ! Next step is to let the world access it.

But before that, cleanup your testing mess:

1
kubectl delete -f ./kubernetes/xx-WhoAmI.yaml

Hey, weโ€™ve done important things here ! Maybe itโ€™s time to commitโ€ฆ

1
2
3
4
git add .
git commit -m "Setup the cluster's internal router

Following guide @ https://gerkindev.github.io/devblog/walkthroughs/kubernetes/03-router/"
Share on

GerkinDev
WRITTEN BY
GerkinDev
Fullstack developer, on its journey to DevOps.

 
What's on this Page