Write an Ingress that routes `/api` to the api service and `/` to the web service with TLS.
IntermediateHands-onWrite-a-Kubernetes-manifest tasks
Answer
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: app
annotations:
cert-manager.io/cluster-issuer: letsencrypt-prod
spec:
ingressClassName: nginx
tls:
- hosts: [app.example.com]
secretName: app-tls
rules:
- host: app.example.com
http:
paths:
- path: /api
pathType: Prefix
backend:
service: { name: api, port: { number: 8080 } }
- path: /
pathType: Prefix
backend:
service: { name: web, port: { number: 80 } }
Key trick → pathType is required in networking.k8s.io/v1, and ingressClassName picks the controller. cert-manager fills the app-tls Secret automatically through the annotation.
More on Write-a-Kubernetes-manifest tasks
Write a Deployment and Service for an Nginx app with 3 replicas, resources and probes.BeginnerAdd an HPA that scales the Deployment between 3 and 15 pods at 70% CPU.BeginnerFix this broken Deployment YAML.BeginnerWrite a ConfigMap and Secret and inject them as environment variables and as a mounted file.IntermediateWrite a pod spec with a hardened securityContext.IntermediateWrite a CronJob that runs a backup every night at 02:00 and keeps limited history.Intermediate