Services & Networking#
This chapter covers how to expose your application within the cluster and to the outside world.
Every kloudease workload cluster comes with its own domain, workload.<project>.<org>.kloudease.tech.
Every name under it, like app.workload.<project>.<org>.kloudease.tech, already points at the cluster. Use it in a Kubernetes Ingress with a handful of annotations - or use workload-helm and autoconfig to configure the ingress automatically.
Services#
The chart creates a primary service called main by default. It's a ClusterIP service with a single http port on 8080.
Changing the Service Port#
If your application listens on a different port, for example 3000, add this to your vaulues.yaml file:
service:
main:
ports:
http:
port: 3000
Validate the new port with by running helm template my-app kloudease/workload-helm -f values.yaml | grep "kind: Service" -A30 | grep "port:" - it should show port: 3000
Adding More Ports#
Additional ports can be added like so:
service:
main:
ports:
http:
port: 8080
primary: true # Used for probes
metrics:
enabled: true
port: 9090
protocol: HTTP
This is useful if the metrics are served from a different port than the application itself.
Multiple Services#
You can define additional services alongside main:
service:
main:
ports:
http:
port: 8080
grpc:
enabled: true
primary: false
type: ClusterIP
ports:
grpc:
enabled: true
port: 50051
protocol: TCP
Ingress#
Ingress is disabled by default. Enable it to route external HTTP(S) traffic to your service.
Autoconfig#
Use autoconfig for the default Kloudease ingress annotations. Set the host name with autoconfig.ingress.host; without it, autoconfig falls back to global.cluster.baseDomain, which you have to set yourself.
Default config:
autoconfig:
ingress:
enabled: true
host: my-app.workload.<project>.<org>.kloudease.tech
Custom host name:
autoconfig:
ingress:
enabled: true
host: "my-app.example.com"
IMPORTANT: For custom host names to work, create a CNAME record for your domain pointing at any name under your cluster's domain, for example my-app.example.com → my-app.workload.<project>.<org>.kloudease.tech. kloudease.tech domains are always included, and always free of charge to use.
Certificate issuer#
Autoconfig uses the cert-manager ClusterIssuer letsencrypt-prod-http (HTTP-01) for every host. It works for your kloudease domain and for your own domains, as long as the name resolves to the cluster.
This is only a default. To use a different issuer, set the annotation explicitly:
autoconfig:
ingress:
enabled: true
annotations:
cert-manager.io/cluster-issuer: <issuer>
Precedence, highest first: autoconfig.ingress.annotations → global.annotations → the default.
When you must override: if the cluster restricts inbound traffic (for example a Traefik LoadBalancer with spec.loadBalancerSourceRanges), HTTP-01 cannot complete. Let's Encrypt does not publish its validation source IPs and validates from multiple changing vantage points, so they cannot be added to an allowlist. Such clusters need DNS-01 on every host, including kloudease.tech ones; contact kloudease Support for the issuer to use.
Note that an existing certificate keeps working until renewal, so a wrong issuer stays invisible for weeks and then fails to renew. Check with:
kubectl get certificate -A -o custom-columns=\
'NS:.metadata.namespace,NAME:.metadata.name,ISSUER:.spec.issuerRef.name,RENEWAL:.status.renewalTime'
Troubleshooting#
If the config is invalid, an error is shown:
Error: execution error at (workload-helm/templates/autoconfig.yaml:35:4): Either global.cluster.baseDomain or autoconfig.ingress.host must be set
If this error is shown, check if values-helm-context is attached to the HelmRelease or set autoconfig.ingress.host.
Custom Ingress#
If need be, a custom Ingress can be configured. It is most of the time not needed, unless there are customizations needed for custom paths or similar.
WE STRONGLY ADVICE AGAINST USING INGRESS DIRECTLY: A custom Ingress is quite complicated, and if underlying architecture changes you may need to migrate your config. It is easier to use autoconfig unless there is a hard requirement for a custom ingress.
Autoconfig can do: - custom annotations - custom labels - custom paths
So there is really no need to do all that by hand.
But if you want to do all of the above by hand, here's how:
Basic ingress
ingress:
main:
enabled: true
hosts:
- host: my-app.example.com
paths:
- path: /
This creates an Ingress resource that routes my-app.example.com/ to the primary service. Traefik is the cluster's default ingress class, so leave ingressClassName unset.
Path Types#
Path can contain any sort of pathType Kubernetes supports:
- Prefix
- Exact
- ImplementationSpecific
ingress:
main:
enabled: true
hosts:
- host: my-app.example.com
paths:
- path: /
pathType: Prefix
- path: /api/v1
pathType: Exact
TLS#
TLS is handled by cert-manager and requires a special annotation:
ingress:
main:
enabled: true
annotation:
# required for SSL certificates, also for your own domains
cert-manager.io/cluster-issuer: "letsencrypt-prod-http"
hosts:
- host: my-app.example.com
paths:
- path: /
tls:
# name of the secret containing the TLS certificate, always <app-name>-tls
- secretName: my-app-tls
hosts:
- my-app.example.com
Multiple Ingresses#
Specify a second config object:
ingress:
main: # <-- main ingress
enabled: true
primary: true
hosts:
- host: app.example.com
paths:
- path: /
admin: # <-- second ingress, named "admin"
enabled: true
primary: false
hosts:
- host: admin.example.com
paths:
- path: /
Network Policies#
Control pod-level network traffic with Kubernetes NetworkPolicies.
Network policies are an advanced mechanism which allows developers to restrict access to their applications. By default, no network policy is applied.
Ingress Rules specify how traffic can reach the application Egress Rules specify how traffic from the application can reach other apps
Deny All Ingress (Default-Deny)#
networkPolicy:
enabled: true
policyTypes:
- Ingress
ingress: [] # Empty = deny all ingress
Allow Specific Ingress#
networkPolicy:
enabled: true
policyTypes:
- Ingress
ingress:
- ports:
- protocol: TCP
port: 8080
from:
- podSelector:
matchLabels:
app.kubernetes.io/name: frontend
The above example allows traffic to port 8080 for pods with the label app.kubernetes.io/name=frontend, all other pods would not be able to access the application.
Ingress + Egress#
networkPolicy:
enabled: true
policyTypes:
- Ingress
- Egress
ingress:
- ports:
- protocol: TCP
port: 8080
from:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: ingress-nginx
egress:
- ports:
- protocol: TCP
port: 5432
to:
- podSelector:
matchLabels:
app.kubernetes.io/name: postgres
Allow Traffic from Monitoring#
A common pattern — allow Prometheus to scrape your metrics port:
networkPolicy:
enabled: true
policyTypes:
- Ingress
ingress:
# Application traffic
- ports:
- protocol: TCP
port: 8080
# Prometheus scraping
- ports:
- protocol: TCP
port: 9090
from:
- podSelector:
matchLabels:
app.kubernetes.io/name: prometheus
namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: monitoring
When to use Network Policies#
Network policies can be used to lock-down a pod more than usual. By default, every app inside Kubernetes can access your application if they know the internal address, which is <service-name>.<namespace>.svc.cluster.local - Network Policies prevent this sort of access.
In a cluster where you or your team are the only developers that may not strictly be necessary. On a shared cluster, or when the data inside an application is sensitive, it makes sense to invest the time into proper network policies.
What's Next#
Your app is exposed. Continue to Configuration to learn how to inject environment variables, ConfigMaps, and Secrets.