Host Based Ingress on Kubernetes Cluster

Part -I
Ingress on Kubernetes Cluster
On Local Cluster Created by using Kubeadm Why Ingress need on Kubernetes? Ingress is a key component in Kubernetes that provides HTTP and HTTPS routing to services based on rules defined by the user. Ingress may provide load balancing, SSL termination and name-based virtual hosting. In this blog, am going

Name Based Virtual Hosting - Demo
Name-based virtual hosts support routing HTTP traffic to multiple host names at the same IP address.

- Create 2 Deployment and Service for demo (to see multi-host purpose)
vi deployment-galaxian-astrion.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: galaxian
labels:
app: galaxian
spec:
replicas: 1
selector:
matchLabels:
app: galaxian
template:
metadata:
labels:
app: galaxian
spec:
containers:
- name: galaxian
image: kubelancer/galaxian:v1
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: galaxian-service
labels:
app: galaxian-service
spec:
type: ClusterIP
ports:
- port: 80
targetPort: 80
protocol: TCP
selector:
app: galaxian
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: astrion
labels:
app: astrion
spec:
replicas: 1
selector:
matchLabels:
app: astrion
template:
metadata:
labels:
app: astrion
spec:
containers:
- name: astrion
image: kubelancer/astrion:v1
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: astrion-service
labels:
app: astrion-service
spec:
type: ClusterIP
ports:
- port: 80
targetPort: 80
protocol: TCP
selector:
app: astrion
- Apply the deployment and service
kubectl apply -f deployment-galaxian-astrion.yaml
- Get Deployments and Pods status
kubectl get deployments,pods,svc
Output

Create multi-host ingress
vi ingress-namebased.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-namebased
spec:
ingressClassName: nginx
rules:
- host: astrion.kubelancer.com
http:
paths:
- backend:
service:
name: astrion-service
port:
number: 80
path: /
pathType: Prefix
- host: galaxian.kubelancer.com
http:
paths:
- backend:
service:
name: galaxian-service
port:
number: 80
path: /
pathType: Prefix
- Apply
kubectl apply -f ingress-namebased.yaml
- Get ingress
kubectl get ingress
Output

Validate
curl --resolve astrion.kubelancer.com:80:192.168.10.0 http://astrion.kubelancer.com
curl --resolve galaxian.kubelancer.com:80:192.168.10.0 http://galaxian.kubelancer.com
Output

Happy Computing 😄