Highly available Load-balancer for Kubernetes Cluster On-Premise - II
Contents
In the first post of this series, haproxy and keepalived installed, configured and tested.
In this post, two stateless Kubernetes web application will be deployed and domain names will be registered to DNS for these two web applications to test if Load-balancer is working as expected.
Note: For my home-lab, I am using the domain nordic.io.
For the Kubernetes cluster, I am assuming that, nginx Ingress controller deployed as DaemonSet and listening on port 80 and port 443 on each worker node.
Deploying Kubernetes Web Applications:
apiVersion: v1
kind: Service
metadata:
name: hello-kubernetes-svc
namespace: default
spec:
ports:
- port: 80
protocol: TCP
targetPort: 8080
selector:
app: hello-kubernetes
sessionAffinity: None
type: ClusterIP
status:
loadBalancer: {}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-kubernetes
spec:
replicas: 3
selector:
matchLabels:
app: hello-kubernetes
template:
metadata:
labels:
app: hello-kubernetes
spec:
containers:
- name: hello-kubernetes
image: paulbouwer/hello-kubernetes:1.8
ports:
- containerPort: 8080
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: hello-kubernetes-ingress
annotations:
ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: helloworld.nordic.io
http:
paths:
- path: /
backend:
serviceName: hello-kubernetes-svc
servicePort: 80
apiVersion: v1
kind: Service
metadata:
name: whoami-svc
namespace: default
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
run: whoami
sessionAffinity: None
type: ClusterIP
status:
loadBalancer: {}
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
run: whoami
name: whoami
namespace: default
spec:
replicas: 1
selector:
matchLabels:
run: whoami
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
run: whoami
spec:
containers:
- image: yeasy/simple-web:latest
name: whoami
restartPolicy: Always
schedulerName: default-scheduler
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: whoami-ingress
annotations:
ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: whoami.nordic.io
http:
paths:
- path: /
backend:
serviceName: whoami-svc
servicePort: 80
Registering Web Apps to DNS:
Adding DNS Records one of the curial part. In order to use single Load Balancer IP to multiple services we are adding CNAME record. You can see bind dns configuration below to make it.
vip1 IN A 10.5.100.50
helloworld IN CNAME vip1
whoami IN CNAME vip1
Experiment:
Checking DNS Records.
[tesla@deployment ~]$ nslookup helloworld
Server: 10.5.100.253
Address: 10.5.100.253#53
helloworld.nordic.io canonical name = vip1.nordic.io.
Name: vip1.nordic.io
Address: 10.5.100.50
[tesla@deployment ~]$ nslookup whoami
Server: 10.5.100.253
Address: 10.5.100.253#53
whoami.nordic.io canonical name = vip1.nordic.io.
Name: vip1.nordic.io
Address: 10.5.100.50