Kubernetes
Ingress Routing
Route external HTTP traffic to services by host and path.
By EZ4Code Team
ingressroutingtls
Code
# ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: api-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
ingressClassName: nginx
rules:
- host: api.example.com
http:
paths:
- path: /v1
pathType: Prefix
backend:
service:
name: api-v1
port: { number: 80 }
- path: /
pathType: Prefix
backend:
service:
name: api-v2
port: { number: 80 }
tls:
- hosts: [api.example.com]
secretName: api-tlsExplanation
An Ingress object routes HTTP/HTTPS traffic to services based on host and path, typically backed by a controller like ingress-nginx. pathType Prefix matches URL prefixes, and the rewrite-target annotation strips the matched path before forwarding. The tls section references a Secret containing the TLS certificate.
More Kubernetes Snippets
Pod Manifest
Define a standalone Pod with a container, env, and probe.
Deployment & Rollout
Manage a replicated, rolling-updated workload.
Service Types
Expose Pods via ClusterIP, NodePort, and LoadBalancer services.
ConfigMap & Secret
Inject configuration and sensitive data into containers.
Labels & Selectors
Tag resources and query them with selectors.
kubectl Basics
Common kubectl commands for everyday operations.