Traefik & CRD & Let’s Encrypt

Traefik with an IngressRoute Custom Resource Definition for Kubernetes, and TLS Through Let’s Encrypt.

This document is intended to be a fully working example demonstrating how to set up Traefik in Kubernetes, with the dynamic configuration coming from the IngressRoute Custom Resource, and TLS setup with Let’s Encrypt. However, for the sake of simplicity, we’re using k3s docker image for the Kubernetes cluster setup.

Please note that for this setup, given that we’re going to use ACME’s TLS-ALPN-01 challenge, the host you’ll be running it on must be able to receive connections from the outside on port 443. And of course its internet facing IP address must match the domain name you intend to use.

In the following, the Kubernetes resources defined in YAML configuration files can be applied to the setup in two different ways:

  • the first, and usual way, is simply with the kubectl apply command.
  • the second, which can be used for this tutorial, is to directly place the files in the directory used by the k3s docker image for such inputs (/var/lib/rancher/k3s/server/manifests).

Kubectl Version

With the rancher/k3s version used in this guide (0.8.0), the kubectl version needs to be >= 1.11.

k3s Docker-compose Configuration

Our starting point is the docker-compose configuration file, to start the k3s cluster. You can start it with:

  1. docker-compose -f k3s.yml up
  1. server:
  2. image: rancher/k3s:v1.17.2-k3s1
  3. command: server --disable-agent --no-deploy traefik
  4. environment:
  5. - K3S_CLUSTER_SECRET=somethingtotallyrandom
  6. - K3S_KUBECONFIG_OUTPUT=/output/kubeconfig.yaml
  7. - K3S_KUBECONFIG_MODE=666
  8. volumes:
  9. # k3s will generate a kubeconfig.yaml in this directory. This volume is mounted
  10. # on your host, so you can then 'export KUBECONFIG=/somewhere/on/your/host/out/kubeconfig.yaml',
  11. # in order for your kubectl commands to work.
  12. - /somewhere/on/your/host/out:/output
  13. # This directory is where you put all the (yaml) configuration files of
  14. # the Kubernetes resources.
  15. - /somewhere/on/your/host/in:/var/lib/rancher/k3s/server/manifests
  16. ports:
  17. - 6443:6443
  18. node:
  19. image: rancher/k3s:v1.17.2-k3s1
  20. privileged: true
  21. links:
  22. - server
  23. environment:
  24. - K3S_URL=https://server:6443
  25. - K3S_CLUSTER_SECRET=somethingtotallyrandom
  26. volumes:
  27. # this is where you would place a alternative traefik image (saved as a .tar file with
  28. # 'docker save'), if you want to use it, instead of the traefik:v2.5 image.
  29. - /sowewhere/on/your/host/custom-image:/var/lib/rancher/k3s/agent/images

Cluster Resources

Let’s now have a look (in the order they should be applied, if using kubectl apply) at all the required resources for the full setup.

IngressRoute Definition

First, the definition of the IngressRoute and the Middleware kinds. Also note the RBAC authorization resources; they’ll be referenced through the serviceAccountName of the deployment, later on.

  1. ---
  2. apiVersion: apiextensions.k8s.io/v1
  3. kind: CustomResourceDefinition
  4. metadata:
  5. annotations:
  6. controller-gen.kubebuilder.io/version: v0.4.1
  7. creationTimestamp: null
  8. name: ingressroutes.traefik.containo.us
  9. spec:
  10. group: traefik.containo.us
  11. names:
  12. kind: IngressRoute
  13. listKind: IngressRouteList
  14. plural: ingressroutes
  15. singular: ingressroute
  16. scope: Namespaced
  17. versions:
  18. - name: v1alpha1
  19. schema:
  20. openAPIV3Schema:
  21. description: IngressRoute is an Ingress CRD specification.
  22. properties:
  23. apiVersion:
  24. description: 'APIVersion defines the versioned schema of this representation
  25. of an object. Servers should convert recognized schemas to the latest
  26. internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
  27. type: string
  28. kind:
  29. description: 'Kind is a string value representing the REST resource this
  30. object represents. Servers may infer this from the endpoint the client
  31. submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
  32. type: string
  33. metadata:
  34. type: object
  35. spec:
  36. description: IngressRouteSpec is a specification for a IngressRouteSpec
  37. resource.
  38. properties:
  39. entryPoints:
  40. items:
  41. type: string
  42. type: array
  43. routes:
  44. items:
  45. description: Route contains the set of routes.
  46. properties:
  47. kind:
  48. enum:
  49. - Rule
  50. type: string
  51. match:
  52. type: string
  53. middlewares:
  54. items:
  55. description: MiddlewareRef is a ref to the Middleware resources.
  56. properties:
  57. name:
  58. type: string
  59. namespace:
  60. type: string
  61. required:
  62. - name
  63. type: object
  64. type: array
  65. priority:
  66. type: integer
  67. services:
  68. items:
  69. description: Service defines an upstream to proxy traffic.
  70. properties:
  71. kind:
  72. enum:
  73. - Service
  74. - TraefikService
  75. type: string
  76. name:
  77. description: Name is a reference to a Kubernetes Service
  78. object (for a load-balancer of servers), or to a TraefikService
  79. object (service load-balancer, mirroring, etc). The
  80. differentiation between the two is specified in the
  81. Kind field.
  82. type: string
  83. namespace:
  84. type: string
  85. passHostHeader:
  86. type: boolean
  87. port:
  88. anyOf:
  89. - type: integer
  90. - type: string
  91. x-kubernetes-int-or-string: true
  92. responseForwarding:
  93. description: ResponseForwarding holds configuration for
  94. the forward of the response.
  95. properties:
  96. flushInterval:
  97. type: string
  98. type: object
  99. scheme:
  100. type: string
  101. serversTransport:
  102. type: string
  103. sticky:
  104. description: Sticky holds the sticky configuration.
  105. properties:
  106. cookie:
  107. description: Cookie holds the sticky configuration
  108. based on cookie.
  109. properties:
  110. httpOnly:
  111. type: boolean
  112. name:
  113. type: string
  114. sameSite:
  115. type: string
  116. secure:
  117. type: boolean
  118. type: object
  119. type: object
  120. strategy:
  121. type: string
  122. weight:
  123. description: Weight should only be specified when Name
  124. references a TraefikService object (and to be precise,
  125. one that embeds a Weighted Round Robin).
  126. type: integer
  127. required:
  128. - name
  129. type: object
  130. type: array
  131. required:
  132. - kind
  133. - match
  134. type: object
  135. type: array
  136. tls:
  137. description: "TLS contains the TLS certificates configuration of the
  138. routes. To enable Let's Encrypt, use an empty TLS struct, e.g. in
  139. YAML: \n \t tls: {} # inline format \n \t tls: \t secretName:
  140. # block format"
  141. properties:
  142. certResolver:
  143. type: string
  144. domains:
  145. items:
  146. description: Domain holds a domain name with SANs.
  147. properties:
  148. main:
  149. type: string
  150. sans:
  151. items:
  152. type: string
  153. type: array
  154. type: object
  155. type: array
  156. options:
  157. description: Options is a reference to a TLSOption, that specifies
  158. the parameters of the TLS connection.
  159. properties:
  160. name:
  161. type: string
  162. namespace:
  163. type: string
  164. required:
  165. - name
  166. type: object
  167. secretName:
  168. description: SecretName is the name of the referenced Kubernetes
  169. Secret to specify the certificate details.
  170. type: string
  171. store:
  172. description: Store is a reference to a TLSStore, that specifies
  173. the parameters of the TLS store.
  174. properties:
  175. name:
  176. type: string
  177. namespace:
  178. type: string
  179. required:
  180. - name
  181. type: object
  182. type: object
  183. required:
  184. - routes
  185. type: object
  186. required:
  187. - metadata
  188. - spec
  189. type: object
  190. served: true
  191. storage: true
  192. status:
  193. acceptedNames:
  194. kind: ""
  195. plural: ""
  196. conditions: []
  197. storedVersions: []
  198. ---
  199. apiVersion: apiextensions.k8s.io/v1
  200. kind: CustomResourceDefinition
  201. metadata:
  202. annotations:
  203. controller-gen.kubebuilder.io/version: v0.4.1
  204. creationTimestamp: null
  205. name: ingressroutetcps.traefik.containo.us
  206. spec:
  207. group: traefik.containo.us
  208. names:
  209. kind: IngressRouteTCP
  210. listKind: IngressRouteTCPList
  211. plural: ingressroutetcps
  212. singular: ingressroutetcp
  213. scope: Namespaced
  214. versions:
  215. - name: v1alpha1
  216. schema:
  217. openAPIV3Schema:
  218. description: IngressRouteTCP is an Ingress CRD specification.
  219. properties:
  220. apiVersion:
  221. description: 'APIVersion defines the versioned schema of this representation
  222. of an object. Servers should convert recognized schemas to the latest
  223. internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
  224. type: string
  225. kind:
  226. description: 'Kind is a string value representing the REST resource this
  227. object represents. Servers may infer this from the endpoint the client
  228. submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
  229. type: string
  230. metadata:
  231. type: object
  232. spec:
  233. description: IngressRouteTCPSpec is a specification for a IngressRouteTCPSpec
  234. resource.
  235. properties:
  236. entryPoints:
  237. items:
  238. type: string
  239. type: array
  240. routes:
  241. items:
  242. description: RouteTCP contains the set of routes.
  243. properties:
  244. match:
  245. type: string
  246. middlewares:
  247. description: Middlewares contains references to MiddlewareTCP
  248. resources.
  249. items:
  250. description: ObjectReference is a generic reference to a Traefik
  251. resource.
  252. properties:
  253. name:
  254. type: string
  255. namespace:
  256. type: string
  257. required:
  258. - name
  259. type: object
  260. type: array
  261. services:
  262. items:
  263. description: ServiceTCP defines an upstream to proxy traffic.
  264. properties:
  265. name:
  266. type: string
  267. namespace:
  268. type: string
  269. port:
  270. anyOf:
  271. - type: integer
  272. - type: string
  273. x-kubernetes-int-or-string: true
  274. proxyProtocol:
  275. description: ProxyProtocol holds the ProxyProtocol configuration.
  276. properties:
  277. version:
  278. type: integer
  279. type: object
  280. terminationDelay:
  281. type: integer
  282. weight:
  283. type: integer
  284. required:
  285. - name
  286. - port
  287. type: object
  288. type: array
  289. required:
  290. - match
  291. type: object
  292. type: array
  293. tls:
  294. description: "TLSTCP contains the TLS certificates configuration of
  295. the routes. To enable Let's Encrypt, use an empty TLS struct, e.g.
  296. in YAML: \n \t tls: {} # inline format \n \t tls: \t secretName:
  297. # block format"
  298. properties:
  299. certResolver:
  300. type: string
  301. domains:
  302. items:
  303. description: Domain holds a domain name with SANs.
  304. properties:
  305. main:
  306. type: string
  307. sans:
  308. items:
  309. type: string
  310. type: array
  311. type: object
  312. type: array
  313. options:
  314. description: Options is a reference to a TLSOption, that specifies
  315. the parameters of the TLS connection.
  316. properties:
  317. name:
  318. type: string
  319. namespace:
  320. type: string
  321. required:
  322. - name
  323. type: object
  324. passthrough:
  325. type: boolean
  326. secretName:
  327. description: SecretName is the name of the referenced Kubernetes
  328. Secret to specify the certificate details.
  329. type: string
  330. store:
  331. description: Store is a reference to a TLSStore, that specifies
  332. the parameters of the TLS store.
  333. properties:
  334. name:
  335. type: string
  336. namespace:
  337. type: string
  338. required:
  339. - name
  340. type: object
  341. type: object
  342. required:
  343. - routes
  344. type: object
  345. required:
  346. - metadata
  347. - spec
  348. type: object
  349. served: true
  350. storage: true
  351. status:
  352. acceptedNames:
  353. kind: ""
  354. plural: ""
  355. conditions: []
  356. storedVersions: []
  357. ---
  358. apiVersion: apiextensions.k8s.io/v1
  359. kind: CustomResourceDefinition
  360. metadata:
  361. annotations:
  362. controller-gen.kubebuilder.io/version: v0.4.1
  363. creationTimestamp: null
  364. name: ingressrouteudps.traefik.containo.us
  365. spec:
  366. group: traefik.containo.us
  367. names:
  368. kind: IngressRouteUDP
  369. listKind: IngressRouteUDPList
  370. plural: ingressrouteudps
  371. singular: ingressrouteudp
  372. scope: Namespaced
  373. versions:
  374. - name: v1alpha1
  375. schema:
  376. openAPIV3Schema:
  377. description: IngressRouteUDP is an Ingress CRD specification.
  378. properties:
  379. apiVersion:
  380. description: 'APIVersion defines the versioned schema of this representation
  381. of an object. Servers should convert recognized schemas to the latest
  382. internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
  383. type: string
  384. kind:
  385. description: 'Kind is a string value representing the REST resource this
  386. object represents. Servers may infer this from the endpoint the client
  387. submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
  388. type: string
  389. metadata:
  390. type: object
  391. spec:
  392. description: IngressRouteUDPSpec is a specification for a IngressRouteUDPSpec
  393. resource.
  394. properties:
  395. entryPoints:
  396. items:
  397. type: string
  398. type: array
  399. routes:
  400. items:
  401. description: RouteUDP contains the set of routes.
  402. properties:
  403. services:
  404. items:
  405. description: ServiceUDP defines an upstream to proxy traffic.
  406. properties:
  407. name:
  408. type: string
  409. namespace:
  410. type: string
  411. port:
  412. anyOf:
  413. - type: integer
  414. - type: string
  415. x-kubernetes-int-or-string: true
  416. weight:
  417. type: integer
  418. required:
  419. - name
  420. - port
  421. type: object
  422. type: array
  423. type: object
  424. type: array
  425. required:
  426. - routes
  427. type: object
  428. required:
  429. - metadata
  430. - spec
  431. type: object
  432. served: true
  433. storage: true
  434. status:
  435. acceptedNames:
  436. kind: ""
  437. plural: ""
  438. conditions: []
  439. storedVersions: []
  440. ---
  441. apiVersion: apiextensions.k8s.io/v1
  442. kind: CustomResourceDefinition
  443. metadata:
  444. annotations:
  445. controller-gen.kubebuilder.io/version: v0.4.1
  446. creationTimestamp: null
  447. name: middlewares.traefik.containo.us
  448. spec:
  449. group: traefik.containo.us
  450. names:
  451. kind: Middleware
  452. listKind: MiddlewareList
  453. plural: middlewares
  454. singular: middleware
  455. scope: Namespaced
  456. versions:
  457. - name: v1alpha1
  458. schema:
  459. openAPIV3Schema:
  460. description: Middleware is a specification for a Middleware resource.
  461. properties:
  462. apiVersion:
  463. description: 'APIVersion defines the versioned schema of this representation
  464. of an object. Servers should convert recognized schemas to the latest
  465. internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
  466. type: string
  467. kind:
  468. description: 'Kind is a string value representing the REST resource this
  469. object represents. Servers may infer this from the endpoint the client
  470. submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
  471. type: string
  472. metadata:
  473. type: object
  474. spec:
  475. description: MiddlewareSpec holds the Middleware configuration.
  476. properties:
  477. addPrefix:
  478. description: AddPrefix holds the AddPrefix configuration.
  479. properties:
  480. prefix:
  481. type: string
  482. type: object
  483. basicAuth:
  484. description: BasicAuth holds the HTTP basic authentication configuration.
  485. properties:
  486. headerField:
  487. type: string
  488. realm:
  489. type: string
  490. removeHeader:
  491. type: boolean
  492. secret:
  493. type: string
  494. type: object
  495. buffering:
  496. description: Buffering holds the request/response buffering configuration.
  497. properties:
  498. maxRequestBodyBytes:
  499. format: int64
  500. type: integer
  501. maxResponseBodyBytes:
  502. format: int64
  503. type: integer
  504. memRequestBodyBytes:
  505. format: int64
  506. type: integer
  507. memResponseBodyBytes:
  508. format: int64
  509. type: integer
  510. retryExpression:
  511. type: string
  512. type: object
  513. chain:
  514. description: Chain holds a chain of middlewares.
  515. properties:
  516. middlewares:
  517. items:
  518. description: MiddlewareRef is a ref to the Middleware resources.
  519. properties:
  520. name:
  521. type: string
  522. namespace:
  523. type: string
  524. required:
  525. - name
  526. type: object
  527. type: array
  528. type: object
  529. circuitBreaker:
  530. description: CircuitBreaker holds the circuit breaker configuration.
  531. properties:
  532. expression:
  533. type: string
  534. type: object
  535. compress:
  536. description: Compress holds the compress configuration.
  537. properties:
  538. excludedContentTypes:
  539. items:
  540. type: string
  541. type: array
  542. type: object
  543. contentType:
  544. description: ContentType middleware - or rather its unique `autoDetect`
  545. option - specifies whether to let the `Content-Type` header, if
  546. it has not been set by the backend, be automatically set to a value
  547. derived from the contents of the response. As a proxy, the default
  548. behavior should be to leave the header alone, regardless of what
  549. the backend did with it. However, the historic default was to always
  550. auto-detect and set the header if it was nil, and it is going to
  551. be kept that way in order to support users currently relying on
  552. it. This middleware exists to enable the correct behavior until
  553. at least the default one can be changed in a future version.
  554. properties:
  555. autoDetect:
  556. type: boolean
  557. type: object
  558. digestAuth:
  559. description: DigestAuth holds the Digest HTTP authentication configuration.
  560. properties:
  561. headerField:
  562. type: string
  563. realm:
  564. type: string
  565. removeHeader:
  566. type: boolean
  567. secret:
  568. type: string
  569. type: object
  570. errors:
  571. description: ErrorPage holds the custom error page configuration.
  572. properties:
  573. query:
  574. type: string
  575. service:
  576. description: Service defines an upstream to proxy traffic.
  577. properties:
  578. kind:
  579. enum:
  580. - Service
  581. - TraefikService
  582. type: string
  583. name:
  584. description: Name is a reference to a Kubernetes Service object
  585. (for a load-balancer of servers), or to a TraefikService
  586. object (service load-balancer, mirroring, etc). The differentiation
  587. between the two is specified in the Kind field.
  588. type: string
  589. namespace:
  590. type: string
  591. passHostHeader:
  592. type: boolean
  593. port:
  594. anyOf:
  595. - type: integer
  596. - type: string
  597. x-kubernetes-int-or-string: true
  598. responseForwarding:
  599. description: ResponseForwarding holds configuration for the
  600. forward of the response.
  601. properties:
  602. flushInterval:
  603. type: string
  604. type: object
  605. scheme:
  606. type: string
  607. serversTransport:
  608. type: string
  609. sticky:
  610. description: Sticky holds the sticky configuration.
  611. properties:
  612. cookie:
  613. description: Cookie holds the sticky configuration based
  614. on cookie.
  615. properties:
  616. httpOnly:
  617. type: boolean
  618. name:
  619. type: string
  620. sameSite:
  621. type: string
  622. secure:
  623. type: boolean
  624. type: object
  625. type: object
  626. strategy:
  627. type: string
  628. weight:
  629. description: Weight should only be specified when Name references
  630. a TraefikService object (and to be precise, one that embeds
  631. a Weighted Round Robin).
  632. type: integer
  633. required:
  634. - name
  635. type: object
  636. status:
  637. items:
  638. type: string
  639. type: array
  640. type: object
  641. forwardAuth:
  642. description: ForwardAuth holds the http forward authentication configuration.
  643. properties:
  644. address:
  645. type: string
  646. authRequestHeaders:
  647. items:
  648. type: string
  649. type: array
  650. authResponseHeaders:
  651. items:
  652. type: string
  653. type: array
  654. authResponseHeadersRegex:
  655. type: string
  656. tls:
  657. description: ClientTLS holds TLS specific configurations as client.
  658. properties:
  659. caOptional:
  660. type: boolean
  661. caSecret:
  662. type: string
  663. certSecret:
  664. type: string
  665. insecureSkipVerify:
  666. type: boolean
  667. type: object
  668. trustForwardHeader:
  669. type: boolean
  670. type: object
  671. headers:
  672. description: Headers holds the custom header configuration.
  673. properties:
  674. accessControlAllowCredentials:
  675. description: AccessControlAllowCredentials is only valid if true.
  676. false is ignored.
  677. type: boolean
  678. accessControlAllowHeaders:
  679. description: AccessControlAllowHeaders must be used in response
  680. to a preflight request with Access-Control-Request-Headers set.
  681. items:
  682. type: string
  683. type: array
  684. accessControlAllowMethods:
  685. description: AccessControlAllowMethods must be used in response
  686. to a preflight request with Access-Control-Request-Method set.
  687. items:
  688. type: string
  689. type: array
  690. accessControlAllowOriginList:
  691. description: AccessControlAllowOriginList is a list of allowable
  692. origins. Can also be a wildcard origin "*".
  693. items:
  694. type: string
  695. type: array
  696. accessControlAllowOriginListRegex:
  697. description: AccessControlAllowOriginListRegex is a list of allowable
  698. origins written following the Regular Expression syntax (https://golang.org/pkg/regexp/).
  699. items:
  700. type: string
  701. type: array
  702. accessControlExposeHeaders:
  703. description: AccessControlExposeHeaders sets valid headers for
  704. the response.
  705. items:
  706. type: string
  707. type: array
  708. accessControlMaxAge:
  709. description: AccessControlMaxAge sets the time that a preflight
  710. request may be cached.
  711. format: int64
  712. type: integer
  713. addVaryHeader:
  714. description: AddVaryHeader controls if the Vary header is automatically
  715. added/updated when the AccessControlAllowOriginList is set.
  716. type: boolean
  717. allowedHosts:
  718. items:
  719. type: string
  720. type: array
  721. browserXssFilter:
  722. type: boolean
  723. contentSecurityPolicy:
  724. type: string
  725. contentTypeNosniff:
  726. type: boolean
  727. customBrowserXSSValue:
  728. type: string
  729. customFrameOptionsValue:
  730. type: string
  731. customRequestHeaders:
  732. additionalProperties:
  733. type: string
  734. type: object
  735. customResponseHeaders:
  736. additionalProperties:
  737. type: string
  738. type: object
  739. featurePolicy:
  740. description: 'Deprecated: use PermissionsPolicy instead.'
  741. type: string
  742. forceSTSHeader:
  743. type: boolean
  744. frameDeny:
  745. type: boolean
  746. hostsProxyHeaders:
  747. items:
  748. type: string
  749. type: array
  750. isDevelopment:
  751. type: boolean
  752. permissionsPolicy:
  753. type: string
  754. publicKey:
  755. type: string
  756. referrerPolicy:
  757. type: string
  758. sslForceHost:
  759. description: 'Deprecated: use RedirectRegex instead.'
  760. type: boolean
  761. sslHost:
  762. description: 'Deprecated: use RedirectRegex instead.'
  763. type: string
  764. sslProxyHeaders:
  765. additionalProperties:
  766. type: string
  767. type: object
  768. sslRedirect:
  769. description: 'Deprecated: use EntryPoint redirection or RedirectScheme
  770. instead.'
  771. type: boolean
  772. sslTemporaryRedirect:
  773. description: 'Deprecated: use EntryPoint redirection or RedirectScheme
  774. instead.'
  775. type: boolean
  776. stsIncludeSubdomains:
  777. type: boolean
  778. stsPreload:
  779. type: boolean
  780. stsSeconds:
  781. format: int64
  782. type: integer
  783. type: object
  784. inFlightReq:
  785. description: InFlightReq limits the number of requests being processed
  786. and served concurrently.
  787. properties:
  788. amount:
  789. format: int64
  790. type: integer
  791. sourceCriterion:
  792. description: SourceCriterion defines what criterion is used to
  793. group requests as originating from a common source. If none
  794. are set, the default is to use the request's remote address
  795. field. All fields are mutually exclusive.
  796. properties:
  797. ipStrategy:
  798. description: IPStrategy holds the ip strategy configuration.
  799. properties:
  800. depth:
  801. type: integer
  802. excludedIPs:
  803. items:
  804. type: string
  805. type: array
  806. type: object
  807. requestHeaderName:
  808. type: string
  809. requestHost:
  810. type: boolean
  811. type: object
  812. type: object
  813. ipWhiteList:
  814. description: IPWhiteList holds the ip white list configuration.
  815. properties:
  816. ipStrategy:
  817. description: IPStrategy holds the ip strategy configuration.
  818. properties:
  819. depth:
  820. type: integer
  821. excludedIPs:
  822. items:
  823. type: string
  824. type: array
  825. type: object
  826. sourceRange:
  827. items:
  828. type: string
  829. type: array
  830. type: object
  831. passTLSClientCert:
  832. description: PassTLSClientCert holds the TLS client cert headers configuration.
  833. properties:
  834. info:
  835. description: TLSClientCertificateInfo holds the client TLS certificate
  836. info configuration.
  837. properties:
  838. issuer:
  839. description: TLSCLientCertificateDNInfo holds the client TLS
  840. certificate distinguished name info configuration. cf https://tools.ietf.org/html/rfc3739
  841. properties:
  842. commonName:
  843. type: boolean
  844. country:
  845. type: boolean
  846. domainComponent:
  847. type: boolean
  848. locality:
  849. type: boolean
  850. organization:
  851. type: boolean
  852. province:
  853. type: boolean
  854. serialNumber:
  855. type: boolean
  856. type: object
  857. notAfter:
  858. type: boolean
  859. notBefore:
  860. type: boolean
  861. sans:
  862. type: boolean
  863. serialNumber:
  864. type: boolean
  865. subject:
  866. description: TLSCLientCertificateDNInfo holds the client TLS
  867. certificate distinguished name info configuration. cf https://tools.ietf.org/html/rfc3739
  868. properties:
  869. commonName:
  870. type: boolean
  871. country:
  872. type: boolean
  873. domainComponent:
  874. type: boolean
  875. locality:
  876. type: boolean
  877. organization:
  878. type: boolean
  879. province:
  880. type: boolean
  881. serialNumber:
  882. type: boolean
  883. type: object
  884. type: object
  885. pem:
  886. type: boolean
  887. type: object
  888. plugin:
  889. additionalProperties:
  890. x-kubernetes-preserve-unknown-fields: true
  891. type: object
  892. rateLimit:
  893. description: RateLimit holds the rate limiting configuration for a
  894. given router.
  895. properties:
  896. average:
  897. format: int64
  898. type: integer
  899. burst:
  900. format: int64
  901. type: integer
  902. period:
  903. anyOf:
  904. - type: integer
  905. - type: string
  906. x-kubernetes-int-or-string: true
  907. sourceCriterion:
  908. description: SourceCriterion defines what criterion is used to
  909. group requests as originating from a common source. If none
  910. are set, the default is to use the request's remote address
  911. field. All fields are mutually exclusive.
  912. properties:
  913. ipStrategy:
  914. description: IPStrategy holds the ip strategy configuration.
  915. properties:
  916. depth:
  917. type: integer
  918. excludedIPs:
  919. items:
  920. type: string
  921. type: array
  922. type: object
  923. requestHeaderName:
  924. type: string
  925. requestHost:
  926. type: boolean
  927. type: object
  928. type: object
  929. redirectRegex:
  930. description: RedirectRegex holds the redirection configuration.
  931. properties:
  932. permanent:
  933. type: boolean
  934. regex:
  935. type: string
  936. replacement:
  937. type: string
  938. type: object
  939. redirectScheme:
  940. description: RedirectScheme holds the scheme redirection configuration.
  941. properties:
  942. permanent:
  943. type: boolean
  944. port:
  945. type: string
  946. scheme:
  947. type: string
  948. type: object
  949. replacePath:
  950. description: ReplacePath holds the ReplacePath configuration.
  951. properties:
  952. path:
  953. type: string
  954. type: object
  955. replacePathRegex:
  956. description: ReplacePathRegex holds the ReplacePathRegex configuration.
  957. properties:
  958. regex:
  959. type: string
  960. replacement:
  961. type: string
  962. type: object
  963. retry:
  964. description: Retry holds the retry configuration.
  965. properties:
  966. attempts:
  967. type: integer
  968. initialInterval:
  969. anyOf:
  970. - type: integer
  971. - type: string
  972. x-kubernetes-int-or-string: true
  973. type: object
  974. stripPrefix:
  975. description: StripPrefix holds the StripPrefix configuration.
  976. properties:
  977. forceSlash:
  978. type: boolean
  979. prefixes:
  980. items:
  981. type: string
  982. type: array
  983. type: object
  984. stripPrefixRegex:
  985. description: StripPrefixRegex holds the StripPrefixRegex configuration.
  986. properties:
  987. regex:
  988. items:
  989. type: string
  990. type: array
  991. type: object
  992. type: object
  993. required:
  994. - metadata
  995. - spec
  996. type: object
  997. served: true
  998. storage: true
  999. status:
  1000. acceptedNames:
  1001. kind: ""
  1002. plural: ""
  1003. conditions: []
  1004. storedVersions: []
  1005. ---
  1006. apiVersion: apiextensions.k8s.io/v1
  1007. kind: CustomResourceDefinition
  1008. metadata:
  1009. annotations:
  1010. controller-gen.kubebuilder.io/version: v0.4.1
  1011. creationTimestamp: null
  1012. name: middlewaretcps.traefik.containo.us
  1013. spec:
  1014. group: traefik.containo.us
  1015. names:
  1016. kind: MiddlewareTCP
  1017. listKind: MiddlewareTCPList
  1018. plural: middlewaretcps
  1019. singular: middlewaretcp
  1020. scope: Namespaced
  1021. versions:
  1022. - name: v1alpha1
  1023. schema:
  1024. openAPIV3Schema:
  1025. description: MiddlewareTCP is a specification for a MiddlewareTCP resource.
  1026. properties:
  1027. apiVersion:
  1028. description: 'APIVersion defines the versioned schema of this representation
  1029. of an object. Servers should convert recognized schemas to the latest
  1030. internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
  1031. type: string
  1032. kind:
  1033. description: 'Kind is a string value representing the REST resource this
  1034. object represents. Servers may infer this from the endpoint the client
  1035. submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
  1036. type: string
  1037. metadata:
  1038. type: object
  1039. spec:
  1040. description: MiddlewareTCPSpec holds the MiddlewareTCP configuration.
  1041. properties:
  1042. ipWhiteList:
  1043. description: TCPIPWhiteList holds the TCP ip white list configuration.
  1044. properties:
  1045. sourceRange:
  1046. items:
  1047. type: string
  1048. type: array
  1049. type: object
  1050. type: object
  1051. required:
  1052. - metadata
  1053. - spec
  1054. type: object
  1055. served: true
  1056. storage: true
  1057. status:
  1058. acceptedNames:
  1059. kind: ""
  1060. plural: ""
  1061. conditions: []
  1062. storedVersions: []
  1063. ---
  1064. apiVersion: apiextensions.k8s.io/v1
  1065. kind: CustomResourceDefinition
  1066. metadata:
  1067. annotations:
  1068. controller-gen.kubebuilder.io/version: v0.4.1
  1069. creationTimestamp: null
  1070. name: serverstransports.traefik.containo.us
  1071. spec:
  1072. group: traefik.containo.us
  1073. names:
  1074. kind: ServersTransport
  1075. listKind: ServersTransportList
  1076. plural: serverstransports
  1077. singular: serverstransport
  1078. scope: Namespaced
  1079. versions:
  1080. - name: v1alpha1
  1081. schema:
  1082. openAPIV3Schema:
  1083. description: ServersTransport is a specification for a ServersTransport resource.
  1084. properties:
  1085. apiVersion:
  1086. description: 'APIVersion defines the versioned schema of this representation
  1087. of an object. Servers should convert recognized schemas to the latest
  1088. internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
  1089. type: string
  1090. kind:
  1091. description: 'Kind is a string value representing the REST resource this
  1092. object represents. Servers may infer this from the endpoint the client
  1093. submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
  1094. type: string
  1095. metadata:
  1096. type: object
  1097. spec:
  1098. description: ServersTransportSpec options to configure communication between
  1099. Traefik and the servers.
  1100. properties:
  1101. certificatesSecrets:
  1102. description: Certificates for mTLS.
  1103. items:
  1104. type: string
  1105. type: array
  1106. disableHTTP2:
  1107. description: Disable HTTP/2 for connections with backend servers.
  1108. type: boolean
  1109. forwardingTimeouts:
  1110. description: Timeouts for requests forwarded to the backend servers.
  1111. properties:
  1112. dialTimeout:
  1113. anyOf:
  1114. - type: integer
  1115. - type: string
  1116. description: The amount of time to wait until a connection to
  1117. a backend server can be established. If zero, no timeout exists.
  1118. x-kubernetes-int-or-string: true
  1119. idleConnTimeout:
  1120. anyOf:
  1121. - type: integer
  1122. - type: string
  1123. description: The maximum period for which an idle HTTP keep-alive
  1124. connection will remain open before closing itself.
  1125. x-kubernetes-int-or-string: true
  1126. responseHeaderTimeout:
  1127. anyOf:
  1128. - type: integer
  1129. - type: string
  1130. description: The amount of time to wait for a server's response
  1131. headers after fully writing the request (including its body,
  1132. if any). If zero, no timeout exists.
  1133. x-kubernetes-int-or-string: true
  1134. type: object
  1135. insecureSkipVerify:
  1136. description: Disable SSL certificate verification.
  1137. type: boolean
  1138. maxIdleConnsPerHost:
  1139. description: If non-zero, controls the maximum idle (keep-alive) to
  1140. keep per-host. If zero, DefaultMaxIdleConnsPerHost is used.
  1141. type: integer
  1142. peerCertURI:
  1143. description: URI used to match against SAN URI during the peer certificate
  1144. verification.
  1145. type: string
  1146. rootCAsSecrets:
  1147. description: Add cert file for self-signed certificate.
  1148. items:
  1149. type: string
  1150. type: array
  1151. serverName:
  1152. description: ServerName used to contact the server.
  1153. type: string
  1154. type: object
  1155. required:
  1156. - metadata
  1157. - spec
  1158. type: object
  1159. served: true
  1160. storage: true
  1161. status:
  1162. acceptedNames:
  1163. kind: ""
  1164. plural: ""
  1165. conditions: []
  1166. storedVersions: []
  1167. ---
  1168. apiVersion: apiextensions.k8s.io/v1
  1169. kind: CustomResourceDefinition
  1170. metadata:
  1171. annotations:
  1172. controller-gen.kubebuilder.io/version: v0.4.1
  1173. creationTimestamp: null
  1174. name: tlsoptions.traefik.containo.us
  1175. spec:
  1176. group: traefik.containo.us
  1177. names:
  1178. kind: TLSOption
  1179. listKind: TLSOptionList
  1180. plural: tlsoptions
  1181. singular: tlsoption
  1182. scope: Namespaced
  1183. versions:
  1184. - name: v1alpha1
  1185. schema:
  1186. openAPIV3Schema:
  1187. description: TLSOption is a specification for a TLSOption resource.
  1188. properties:
  1189. apiVersion:
  1190. description: 'APIVersion defines the versioned schema of this representation
  1191. of an object. Servers should convert recognized schemas to the latest
  1192. internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
  1193. type: string
  1194. kind:
  1195. description: 'Kind is a string value representing the REST resource this
  1196. object represents. Servers may infer this from the endpoint the client
  1197. submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
  1198. type: string
  1199. metadata:
  1200. type: object
  1201. spec:
  1202. description: TLSOptionSpec configures TLS for an entry point.
  1203. properties:
  1204. alpnProtocols:
  1205. items:
  1206. type: string
  1207. type: array
  1208. cipherSuites:
  1209. items:
  1210. type: string
  1211. type: array
  1212. clientAuth:
  1213. description: ClientAuth defines the parameters of the client authentication
  1214. part of the TLS connection, if any.
  1215. properties:
  1216. clientAuthType:
  1217. description: ClientAuthType defines the client authentication
  1218. type to apply.
  1219. enum:
  1220. - NoClientCert
  1221. - RequestClientCert
  1222. - VerifyClientCertIfGiven
  1223. - RequireAndVerifyClientCert
  1224. type: string
  1225. secretNames:
  1226. description: SecretName is the name of the referenced Kubernetes
  1227. Secret to specify the certificate details.
  1228. items:
  1229. type: string
  1230. type: array
  1231. type: object
  1232. curvePreferences:
  1233. items:
  1234. type: string
  1235. type: array
  1236. maxVersion:
  1237. type: string
  1238. minVersion:
  1239. type: string
  1240. preferServerCipherSuites:
  1241. type: boolean
  1242. sniStrict:
  1243. type: boolean
  1244. type: object
  1245. required:
  1246. - metadata
  1247. - spec
  1248. type: object
  1249. served: true
  1250. storage: true
  1251. status:
  1252. acceptedNames:
  1253. kind: ""
  1254. plural: ""
  1255. conditions: []
  1256. storedVersions: []
  1257. ---
  1258. apiVersion: apiextensions.k8s.io/v1
  1259. kind: CustomResourceDefinition
  1260. metadata:
  1261. annotations:
  1262. controller-gen.kubebuilder.io/version: v0.4.1
  1263. creationTimestamp: null
  1264. name: tlsstores.traefik.containo.us
  1265. spec:
  1266. group: traefik.containo.us
  1267. names:
  1268. kind: TLSStore
  1269. listKind: TLSStoreList
  1270. plural: tlsstores
  1271. singular: tlsstore
  1272. scope: Namespaced
  1273. versions:
  1274. - name: v1alpha1
  1275. schema:
  1276. openAPIV3Schema:
  1277. description: TLSStore is a specification for a TLSStore resource.
  1278. properties:
  1279. apiVersion:
  1280. description: 'APIVersion defines the versioned schema of this representation
  1281. of an object. Servers should convert recognized schemas to the latest
  1282. internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
  1283. type: string
  1284. kind:
  1285. description: 'Kind is a string value representing the REST resource this
  1286. object represents. Servers may infer this from the endpoint the client
  1287. submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
  1288. type: string
  1289. metadata:
  1290. type: object
  1291. spec:
  1292. description: TLSStoreSpec configures a TLSStore resource.
  1293. properties:
  1294. defaultCertificate:
  1295. description: DefaultCertificate holds a secret name for the TLSOption
  1296. resource.
  1297. properties:
  1298. secretName:
  1299. description: SecretName is the name of the referenced Kubernetes
  1300. Secret to specify the certificate details.
  1301. type: string
  1302. required:
  1303. - secretName
  1304. type: object
  1305. required:
  1306. - defaultCertificate
  1307. type: object
  1308. required:
  1309. - metadata
  1310. - spec
  1311. type: object
  1312. served: true
  1313. storage: true
  1314. status:
  1315. acceptedNames:
  1316. kind: ""
  1317. plural: ""
  1318. conditions: []
  1319. storedVersions: []
  1320. ---
  1321. apiVersion: apiextensions.k8s.io/v1
  1322. kind: CustomResourceDefinition
  1323. metadata:
  1324. annotations:
  1325. controller-gen.kubebuilder.io/version: v0.4.1
  1326. creationTimestamp: null
  1327. name: traefikservices.traefik.containo.us
  1328. spec:
  1329. group: traefik.containo.us
  1330. names:
  1331. kind: TraefikService
  1332. listKind: TraefikServiceList
  1333. plural: traefikservices
  1334. singular: traefikservice
  1335. scope: Namespaced
  1336. versions:
  1337. - name: v1alpha1
  1338. schema:
  1339. openAPIV3Schema:
  1340. description: TraefikService is the specification for a service (that an IngressRoute
  1341. refers to) that is usually not a terminal service (i.e. not a pod of servers),
  1342. as opposed to a Kubernetes Service. That is to say, it usually refers to
  1343. other (children) services, which themselves can be TraefikServices or Services.
  1344. properties:
  1345. apiVersion:
  1346. description: 'APIVersion defines the versioned schema of this representation
  1347. of an object. Servers should convert recognized schemas to the latest
  1348. internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
  1349. type: string
  1350. kind:
  1351. description: 'Kind is a string value representing the REST resource this
  1352. object represents. Servers may infer this from the endpoint the client
  1353. submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
  1354. type: string
  1355. metadata:
  1356. type: object
  1357. spec:
  1358. description: ServiceSpec defines whether a TraefikService is a load-balancer
  1359. of services or a mirroring service.
  1360. properties:
  1361. mirroring:
  1362. description: Mirroring defines a mirroring service, which is composed
  1363. of a main load-balancer, and a list of mirrors.
  1364. properties:
  1365. kind:
  1366. enum:
  1367. - Service
  1368. - TraefikService
  1369. type: string
  1370. maxBodySize:
  1371. format: int64
  1372. type: integer
  1373. mirrors:
  1374. items:
  1375. description: MirrorService defines one of the mirrors of a Mirroring
  1376. service.
  1377. properties:
  1378. kind:
  1379. enum:
  1380. - Service
  1381. - TraefikService
  1382. type: string
  1383. name:
  1384. description: Name is a reference to a Kubernetes Service
  1385. object (for a load-balancer of servers), or to a TraefikService
  1386. object (service load-balancer, mirroring, etc). The differentiation
  1387. between the two is specified in the Kind field.
  1388. type: string
  1389. namespace:
  1390. type: string
  1391. passHostHeader:
  1392. type: boolean
  1393. percent:
  1394. type: integer
  1395. port:
  1396. anyOf:
  1397. - type: integer
  1398. - type: string
  1399. x-kubernetes-int-or-string: true
  1400. responseForwarding:
  1401. description: ResponseForwarding holds configuration for
  1402. the forward of the response.
  1403. properties:
  1404. flushInterval:
  1405. type: string
  1406. type: object
  1407. scheme:
  1408. type: string
  1409. serversTransport:
  1410. type: string
  1411. sticky:
  1412. description: Sticky holds the sticky configuration.
  1413. properties:
  1414. cookie:
  1415. description: Cookie holds the sticky configuration based
  1416. on cookie.
  1417. properties:
  1418. httpOnly:
  1419. type: boolean
  1420. name:
  1421. type: string
  1422. sameSite:
  1423. type: string
  1424. secure:
  1425. type: boolean
  1426. type: object
  1427. type: object
  1428. strategy:
  1429. type: string
  1430. weight:
  1431. description: Weight should only be specified when Name references
  1432. a TraefikService object (and to be precise, one that embeds
  1433. a Weighted Round Robin).
  1434. type: integer
  1435. required:
  1436. - name
  1437. type: object
  1438. type: array
  1439. name:
  1440. description: Name is a reference to a Kubernetes Service object
  1441. (for a load-balancer of servers), or to a TraefikService object
  1442. (service load-balancer, mirroring, etc). The differentiation
  1443. between the two is specified in the Kind field.
  1444. type: string
  1445. namespace:
  1446. type: string
  1447. passHostHeader:
  1448. type: boolean
  1449. port:
  1450. anyOf:
  1451. - type: integer
  1452. - type: string
  1453. x-kubernetes-int-or-string: true
  1454. responseForwarding:
  1455. description: ResponseForwarding holds configuration for the forward
  1456. of the response.
  1457. properties:
  1458. flushInterval:
  1459. type: string
  1460. type: object
  1461. scheme:
  1462. type: string
  1463. serversTransport:
  1464. type: string
  1465. sticky:
  1466. description: Sticky holds the sticky configuration.
  1467. properties:
  1468. cookie:
  1469. description: Cookie holds the sticky configuration based on
  1470. cookie.
  1471. properties:
  1472. httpOnly:
  1473. type: boolean
  1474. name:
  1475. type: string
  1476. sameSite:
  1477. type: string
  1478. secure:
  1479. type: boolean
  1480. type: object
  1481. type: object
  1482. strategy:
  1483. type: string
  1484. weight:
  1485. description: Weight should only be specified when Name references
  1486. a TraefikService object (and to be precise, one that embeds
  1487. a Weighted Round Robin).
  1488. type: integer
  1489. required:
  1490. - name
  1491. type: object
  1492. weighted:
  1493. description: WeightedRoundRobin defines a load-balancer of services.
  1494. properties:
  1495. services:
  1496. items:
  1497. description: Service defines an upstream to proxy traffic.
  1498. properties:
  1499. kind:
  1500. enum:
  1501. - Service
  1502. - TraefikService
  1503. type: string
  1504. name:
  1505. description: Name is a reference to a Kubernetes Service
  1506. object (for a load-balancer of servers), or to a TraefikService
  1507. object (service load-balancer, mirroring, etc). The differentiation
  1508. between the two is specified in the Kind field.
  1509. type: string
  1510. namespace:
  1511. type: string
  1512. passHostHeader:
  1513. type: boolean
  1514. port:
  1515. anyOf:
  1516. - type: integer
  1517. - type: string
  1518. x-kubernetes-int-or-string: true
  1519. responseForwarding:
  1520. description: ResponseForwarding holds configuration for
  1521. the forward of the response.
  1522. properties:
  1523. flushInterval:
  1524. type: string
  1525. type: object
  1526. scheme:
  1527. type: string
  1528. serversTransport:
  1529. type: string
  1530. sticky:
  1531. description: Sticky holds the sticky configuration.
  1532. properties:
  1533. cookie:
  1534. description: Cookie holds the sticky configuration based
  1535. on cookie.
  1536. properties:
  1537. httpOnly:
  1538. type: boolean
  1539. name:
  1540. type: string
  1541. sameSite:
  1542. type: string
  1543. secure:
  1544. type: boolean
  1545. type: object
  1546. type: object
  1547. strategy:
  1548. type: string
  1549. weight:
  1550. description: Weight should only be specified when Name references
  1551. a TraefikService object (and to be precise, one that embeds
  1552. a Weighted Round Robin).
  1553. type: integer
  1554. required:
  1555. - name
  1556. type: object
  1557. type: array
  1558. sticky:
  1559. description: Sticky holds the sticky configuration.
  1560. properties:
  1561. cookie:
  1562. description: Cookie holds the sticky configuration based on
  1563. cookie.
  1564. properties:
  1565. httpOnly:
  1566. type: boolean
  1567. name:
  1568. type: string
  1569. sameSite:
  1570. type: string
  1571. secure:
  1572. type: boolean
  1573. type: object
  1574. type: object
  1575. type: object
  1576. type: object
  1577. required:
  1578. - metadata
  1579. - spec
  1580. type: object
  1581. served: true
  1582. storage: true
  1583. status:
  1584. acceptedNames:
  1585. kind: ""
  1586. plural: ""
  1587. conditions: []
  1588. storedVersions: []
  1589. ---
  1590. kind: ClusterRole
  1591. apiVersion: rbac.authorization.k8s.io/v1beta1
  1592. metadata:
  1593. name: traefik-ingress-controller
  1594. rules:
  1595. - apiGroups:
  1596. - ""
  1597. resources:
  1598. - services
  1599. - endpoints
  1600. - secrets
  1601. verbs:
  1602. - get
  1603. - list
  1604. - watch
  1605. - apiGroups:
  1606. - extensions
  1607. - networking.k8s.io
  1608. resources:
  1609. - ingresses
  1610. - ingressclasses
  1611. verbs:
  1612. - get
  1613. - list
  1614. - watch
  1615. - apiGroups:
  1616. - extensions
  1617. resources:
  1618. - ingresses/status
  1619. verbs:
  1620. - update
  1621. - apiGroups:
  1622. - traefik.containo.us
  1623. resources:
  1624. - middlewares
  1625. - middlewaretcps
  1626. - ingressroutes
  1627. - traefikservices
  1628. - ingressroutetcps
  1629. - ingressrouteudps
  1630. - tlsoptions
  1631. - tlsstores
  1632. - serverstransports
  1633. verbs:
  1634. - get
  1635. - list
  1636. - watch
  1637. ---
  1638. kind: ClusterRoleBinding
  1639. apiVersion: rbac.authorization.k8s.io/v1beta1
  1640. metadata:
  1641. name: traefik-ingress-controller
  1642. roleRef:
  1643. apiGroup: rbac.authorization.k8s.io
  1644. kind: ClusterRole
  1645. name: traefik-ingress-controller
  1646. subjects:
  1647. - kind: ServiceAccount
  1648. name: traefik-ingress-controller
  1649. namespace: default

Services

Then, the services. One for Traefik itself, and one for the app it routes for, i.e. in this case our demo HTTP server: whoami.

  1. apiVersion: v1
  2. kind: Service
  3. metadata:
  4. name: traefik
  5. spec:
  6. ports:
  7. - protocol: TCP
  8. name: web
  9. port: 8000
  10. - protocol: TCP
  11. name: admin
  12. port: 8080
  13. - protocol: TCP
  14. name: websecure
  15. port: 4443
  16. selector:
  17. app: traefik
  18. ---
  19. apiVersion: v1
  20. kind: Service
  21. metadata:
  22. name: whoami
  23. spec:
  24. ports:
  25. - protocol: TCP
  26. name: web
  27. port: 80
  28. selector:
  29. app: whoami

Deployments

Next, the deployments, i.e. the actual pods behind the services. Again, one pod for Traefik, and one for the whoami app.

  1. apiVersion: v1
  2. kind: ServiceAccount
  3. metadata:
  4. namespace: default
  5. name: traefik-ingress-controller
  6. ---
  7. kind: Deployment
  8. apiVersion: apps/v1
  9. metadata:
  10. namespace: default
  11. name: traefik
  12. labels:
  13. app: traefik
  14. spec:
  15. replicas: 1
  16. selector:
  17. matchLabels:
  18. app: traefik
  19. template:
  20. metadata:
  21. labels:
  22. app: traefik
  23. spec:
  24. serviceAccountName: traefik-ingress-controller
  25. containers:
  26. - name: traefik
  27. image: traefik:v2.5
  28. args:
  29. - --api.insecure
  30. - --accesslog
  31. - --entrypoints.web.Address=:8000
  32. - --entrypoints.websecure.Address=:4443
  33. - --providers.kubernetescrd
  34. - --certificatesresolvers.myresolver.acme.tlschallenge
  35. - --certificatesresolvers.myresolver.acme.email=foo@you.com
  36. - --certificatesresolvers.myresolver.acme.storage=acme.json
  37. # Please note that this is the staging Let's Encrypt server.
  38. # Once you get things working, you should remove that whole line altogether.
  39. - --certificatesresolvers.myresolver.acme.caserver=https://acme-staging-v02.api.letsencrypt.org/directory
  40. ports:
  41. - name: web
  42. containerPort: 8000
  43. - name: websecure
  44. containerPort: 4443
  45. - name: admin
  46. containerPort: 8080
  47. ---
  48. kind: Deployment
  49. apiVersion: apps/v1
  50. metadata:
  51. namespace: default
  52. name: whoami
  53. labels:
  54. app: whoami
  55. spec:
  56. replicas: 2
  57. selector:
  58. matchLabels:
  59. app: whoami
  60. template:
  61. metadata:
  62. labels:
  63. app: whoami
  64. spec:
  65. containers:
  66. - name: whoami
  67. image: traefik/whoami
  68. ports:
  69. - name: web
  70. containerPort: 80

Port Forwarding

Now, as an exception to what we said above, please note that you should not let the ingressRoute resources below be applied automatically to your cluster. The reason is, as soon as the ACME provider of Traefik detects we have TLS routers, it will try to generate the certificates for the corresponding domains. And this will not work, because as it is, our Traefik pod is not reachable from the outside, which will make the ACME TLS challenge fail. Therefore, for the whole thing to work, we must delay applying the ingressRoute resources until we have port-forwarding set up properly, which is the next step.

  1. kubectl port-forward --address 0.0.0.0 service/traefik 8000:8000 8080:8080 443:4443 -n default

Also, and this is out of the scope if this guide, please note that because of the privileged ports limitation on Linux, the above command might fail to listen on port 443. In which case you can use tricks such as elevating caps of kubectl with setcaps, or using authbind, or setting up a NAT between your host and the WAN. Look it up.

Traefik Routers

We can now finally apply the actual ingressRoutes, with:

  1. kubectl apply -f 04-ingressroutes.yml
  1. apiVersion: traefik.containo.us/v1alpha1
  2. kind: IngressRoute
  3. metadata:
  4. name: simpleingressroute
  5. namespace: default
  6. spec:
  7. entryPoints:
  8. - web
  9. routes:
  10. - match: Host(`your.example.com`) && PathPrefix(`/notls`)
  11. kind: Rule
  12. services:
  13. - name: whoami
  14. port: 80
  15. ---
  16. apiVersion: traefik.containo.us/v1alpha1
  17. kind: IngressRoute
  18. metadata:
  19. name: ingressroutetls
  20. namespace: default
  21. spec:
  22. entryPoints:
  23. - websecure
  24. routes:
  25. - match: Host(`your.example.com`) && PathPrefix(`/tls`)
  26. kind: Rule
  27. services:
  28. - name: whoami
  29. port: 80
  30. tls:
  31. certResolver: myresolver

Give it a few seconds for the ACME TLS challenge to complete, and you should then be able to access your whoami pod (routed through Traefik), from the outside. Both with or (just for fun, do not do that in production) without TLS:

  1. curl [-k] https://your.example.com/tls
  1. curl http://your.example.com:8000/notls

Note that you’ll have to use -k as long as you’re using the staging server of Let’s Encrypt, since it is not an authorized certificate authority on systems where it hasn’t been manually added.