In order to learn a bit more about K8S I started running a single server/node K3S cluster as a home lab. But I believe I've reached an impasse on my understanding of the network model, maybe specific to K3S.
So far so good, except I wanted to apply a TLS certificate to some services+ingresses I have set up.
In one of them, I have configured a TLS certificate as a secret and applied it to the Ingress associated with the service, however I always get the TRAEFIK DEFAULT CERT, which you can see here.
As I understand it, K3S comes with Traefik and ServiceLB pre-packaged in order to not rely on cloud-services' external load balancers (AWS etc). My first guess was that Traefik would "discover" the routes setup in my Ingress and proxy the TLS traffic, thus using the certificate I set up. This is clearly not the case, so I suppose I need to set up a TLS certificate for the Traefik instance itself.
My questions are then
- How can I set up this certificate in K3S, and do I need a wildcard certificate if I'm planning on having multiple projects/domains hitting this cluster? (I would prefer managing the certificates per project)
- What are the roles of ServiceLB and Traefik in K3S network model? If Traefik is getting the 80 and 443 traffic, is it just forwarding the traffic to ServiceLB which then forwards it to the Ingress resource?
In case it's needed, here's my ingress/service configuration
resource kubernetes_service_v1 snitch_service {
metadata {
name = "snitch"
namespace = module.namespace.name
}
spec {
selector = {
app = "snitch"
}
type = "LoadBalancer"
port {
name = "main"
port = 3010
target_port = 3000
node_port = 30003
}
}
}
resource kubernetes_secret_v1 tls_secret {
metadata {
name = "snitch-tls-cert"
namespace = "my-namespace"
}
type = "kubernetes.io/tls"
data = {
"tls.crt" = base64encode(my_certificate)
"tls.key" = base64encode(my_certificate_private_key)
}
}
resource kubernetes_ingress_v1 snitch_ingress {
metadata {
name = "snitch"
namespace = "my-namespace"
annotations = {
"ingress.kubernetes.io/ssl-redirect" = "false"
}
}
spec {
tls {
hosts = [local.subdomain]
secret_name = "snitch-tls-cert"
}
rule {
host = local.subdomain
http {
path {
path = "/"
path_type = "Prefix"
backend {
service {
name = "snitch"
port {
number = 3010
}
}
}
}
}
}
}
}
Thank you!