What is Ingress
Let's learn about Kubernetes Ingress
Reference: Kubernetes docs
Ingress
Generally, network traffic is classified into
ingressandegressIngress is incoming network traffic from outside to inside the server
Egress is outgoing network traffic from inside the server to outside
An API Object that manages external access to services within a cluster
Typically manages
HTTPS
Ingress can provide load balancing, SSL termination, and name-based virtual hosting
Terms
Node
Part of a cluster
A worker machine belonging to Kubernetes
Cluster
A set of nodes that run containerized applications managed by Kubernetes
In most Kubernetes deployments, nodes in the cluster are not part of the
Public Internet
Edge Router
A router that enforces firewall policies for the cluster
Could be a
Gatewaymanaged by a cloud provider or physical hardware
Cluster Network
A set of logical or physical links that facilitate communication within the cluster according to the Kubernetes networking model
Service
A Kubernetes service that identifies a set of
podsusing aLabel selectorUnless otherwise mentioned, it is assumed that services have virtual IPs that are only routable within the
Cluster network
What is Ingress?
Exposes HTTP and HTTPS routes from outside the cluster to services inside the cluster
Traffic routing is controlled by rules defined on the Ingress resource

Ingress can be configured to provide externally-reachable URLs for services, load balance traffic, SSL/TLS termination, and name-based virtual hosting services
An
Ingress controlleris typically responsible for fulfilling the Ingress using a load balancer, and it can also configure an edge router or additional frontends to help handle traffic
Ingress does not expose arbitrary ports or protocols
To expose services other than HTTP and HTTPS to the internet, you typically use
Service.Type=NodePortorService.Type=LoadBalancer
Prerequisites
An
Ingress Controlleris required to fulfill anIngressSimply creating the resource has no effect! A controller is needed
You need to deploy an ingress controller such as
ingress-nginx, and there are various types of ingress controllers available
The Ingress resource
A minimal Ingress resource example
Like all other Kubernetes resources, an Ingress requires
apiVersion,kind, andmetadatafieldsThe name of an Ingress object must be a valid DNS subdomain name
Ingress frequently uses annotations to configure various options depending on the ingress controller, such as the rewrite-target annotation
Different ingress controllers support different annotations
The
Ingress speccontains all the information needed to configure a load balancer or proxy serverMost importantly, it contains a list of rules that match incoming requests
The Ingress resource only supports rules for directing HTTP(S) traffic
Ingress rules
: Each HTTP rule contains the following information
Optional host
If a host is provided, the rules apply to that host
List of paths
Each path in the list has an associated backend defined with
service.name,service.port.nameorservice.port.numberBoth the host and path must match the content of an incoming request before the load balancer directs traffic to the referenced service
Backend
A backend is a combination of service and port name as described in the service docs or custom resource backends
HTTP(S) requests to the Ingress that match the host and rule path are sent to the listed backends
DefaultBackend
An Ingress with no rules sends all traffic to a single default backend
The DefaultBackend is a configuration option of the
ingress controllerand is not specified in theingress resourceIf no host or path matches the HTTP request of the
ingress object, the traffic is routed to the default backend
Resource Backend
A
Resource backendis an ObjectRef to another Kubernetes resource within the same namespace as the Ingress objectA
Resourceis a mutually exclusive setting with service, and specifying both will fail validationValidation will fail
A common use of
Resource backendis to ingest data into an object storage backend with static assets
Resource backend example
After creating the Ingress with the YAML file above, you can verify the created Ingress with the following command
Result
Path types
Each path in an Ingress must have a corresponding path type
Paths that do not include an explicit
pathTypewill fail validation!
There are three supported path types
ImplementationSpecificWhether this path type matches depends on the IngressClass
Implementations can treat this as a separate
pathType,Or treat it like
PrefixorExactpath types
ExactMatches the URL path with case sensitivity strictly
PrefixMatches based on a URL path prefix split by
/Matching is case-sensitive,
And done on a path element by element basis
A request matches path p if every element-wise prefix of the request path is p
However, it does not match if the last element of the path is a substring of the last element in the request path
ex)
/foo/barmatches/foo/bar/baz,but
/foo/bardoes not match/foo/barbaz!
Examples
Prefix
/
(all paths)
Yes
Exact
/foo
/foo
Yes
Exact
/foo
/bar
No
Exact
/foo
/foo/
No
Exact
/foo/
/foo
No
Prefix
/foo
/foo, /foo/
Yes
Prefix
/foo/
/foo, /foo/
Yes
Prefix
/aaa/bb
/aaa/bbb
No
Prefix
/aaa/bbb
/aaa/bbb
Yes
Prefix
/aaa/bbb/
/aaa/bbb
Yes, trailing slash ignored
Prefix
/aaa/bbb
/aaa/bbb/
Yes, trailing slash matches
Prefix
/aaa/bbb
/aaa/bbb/ccc
Yes, subpath matches
Prefix
/aaa/bbb
/aaa/bbbxyz
No, string prefix does not match
Prefix
/, /aaa
/aaa/ccc
Yes, /aaa prefix matches
Prefix
/, /aaa, /aaa/bbb
/aaa/bbb
Yes, /aaa/bbb prefix matches
Prefix
/, /aaa, /aaa/bbb
/ccc
Yes, / prefix matches
Prefix
/aaa
/ccc
No, uses default backend
Mixed
/foo (Prefix), /foo (Exact)
/foo
Yes, Exact is preferred
Multiple matches
In some cases, multiple paths in an Ingress may match a request
In such cases, the longest matching path takes precedence
If two paths have the same length, the path with an
Exactpath type is used over one with aPrefixpath type!
+
Kubernetes services balance Pods at the
L4 layer, at theTCPlevel
Last updated