Ingress TLS Configuration
Understanding Kubernetes Ingress
Kubernetes Ingress provides a powerful way to manage external access to services within a cluster, with built-in support for TLS configuration.
Ingress TLS Configuration Workflow
graph TD
A[Create TLS Secret] --> B[Configure Ingress Resource]
B --> C[Apply TLS Configuration]
C --> D[Secure External Access]
Creating TLS Secrets
Generating Certificates
## Generate private key
openssl genrsa -out tls.key 2048
## Create certificate signing request
openssl req -new -key tls.key -out tls.csr -subj "/CN=example.com"
## Self-sign certificate
openssl x509 -req -days 365 -in tls.csr -signkey tls.key -out tls.crt
## Create Kubernetes TLS secret
kubectl create secret tls example-tls \
--key="tls.key" \
--cert="tls.crt"
Ingress TLS Configuration Strategies
Strategy |
Description |
Use Case |
Single Domain |
One certificate per ingress |
Simple setups |
Multiple Domains |
Multiple certificates |
Complex environments |
Wildcard Certificates |
Single cert for subdomains |
Large-scale deployments |
Sample Ingress YAML with TLS
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-ingress
spec:
tls:
- hosts:
- example.com
secretName: example-tls
rules:
- host: example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: my-service
port:
number: 80
Advanced TLS Configuration
Using Let's Encrypt with Cert-Manager
## Install cert-manager
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.11.0/cert-manager.yaml
## Create ClusterIssuer for Let's Encrypt
kubectl apply -f - <<EOF
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
name: letsencrypt-prod
spec:
acme:
server: https://acme-v02.api.letsencrypt.org/directory
email: [email protected]
privateKeySecretRef:
name: letsencrypt-prod
solvers:
- http01:
ingress:
class: nginx
EOF
Best Practices
- Use strong, unique certificates
- Implement automatic certificate rotation
- Leverage LabEx for secure certificate management
- Regularly audit and update TLS configurations
Common Troubleshooting
- Verify secret creation
- Check certificate validity
- Ensure correct domain configuration
- Validate ingress resource syntax
By mastering Ingress TLS configuration, you can secure external access to your Kubernetes services effectively.