Ingress YAML
- Docker & Kubernetes course
- Advanced
- Lesson 3/70
- 4 min
Learn the Ingress resource YAML structure.
Ingress YAML
Ingress rules are listed under rules; each rule contains a host and a list of paths. Each path goes to a backend service:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: magaza
spec:
ingressClassName: nginx
rules:
- host: magaza.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: web
port:
number: 80
The default backend
Requests matching no rule go to the defaultBackend; if it isn't defined, the controller returns 404. A rule with no host accepts all domain names:
spec:
ingressClassName: nginx
defaultBackend:
service:
name: bulunamadi
port:
number: 80
rules:
- http: # no host: all names
paths:
- path: /
pathType: Prefix
backend:
service: {name: web, port: {number: 80}}Practice Write an Ingress
Write an Ingress YAML: name magaza; ingressClassName: nginx; host magaza.example.com; the / path (pathType: Prefix) goes to port 80 of the web service.
Starter code
# buraya yazSample solution
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: magaza
spec:
ingressClassName: nginx
rules:
- host: magaza.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: web
port:
number: 80Expected output
ingress.networking.k8s.io/magaza created
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What is the Ingress's apiVersion?
- extensions/v1beta1
- networking.k8s.io/v1 Correct answer
- v1
- apps/v1
Explanation: extensions/v1beta1 is the old, removed version.
2 Give the backend service's port.
backend:
service:
name: web
port:
____: 80
backend:
service:
name: web
port:
number: 80
Explanation: The port is given either with number or with name.
3 Match.
| Term | Meaning |
|---|---|
rules |
Rule list |
host |
Domain name |
backend.service |
Target service |
defaultBackend |
Unmatched requests |