Open shift , automatically load balancer and fail‐over , Jenkins as a sample deployment - unix1998/technical_notes GitHub Wiki
When we deploy Jenkins with 3 replicas on OpenShift and expose it through a route, OpenShift's routing layer (which uses HAProxy by default) will automatically provide load balancing and failover across the replicas. Here's how it works:
-
Deployment with Replicas: When you create a Jenkins deployment with 3 replicas, OpenShift will ensure that there are 3 running instances (pods) of Jenkins.
-
Service Exposure: You create a service that selects these pods, and this service will automatically load balance traffic among the replicas.
-
Route Creation: When you create a route to expose your service, OpenShift uses HAProxy to manage the routing. The route will distribute incoming traffic across the different pods based on the service.
-
Load Balancing: HAProxy, configured by OpenShift, will handle the load balancing. It will direct incoming traffic to the different pods based on the algorithm configured (usually round-robin by default).
-
Failover: If one of the Jenkins pods fails, Kubernetes/OpenShift will automatically replace it with a new pod to maintain the desired number of replicas. The service and route will then automatically reroute traffic to the healthy pods.
Steps to Deploy Jenkins with 3 Replicas and Expose It:
-
Deploy Jenkins with Replicas:
apiVersion: apps/v1 kind: Deployment metadata: name: jenkins spec: replicas: 3 selector: matchLabels: app: jenkins template: metadata: labels: app: jenkins spec: containers: - name: jenkins image: jenkins/jenkins:lts ports: - containerPort: 8080
-
Create a Service:
apiVersion: v1 kind: Service metadata: name: jenkins spec: selector: app: jenkins ports: - protocol: TCP port: 80 targetPort: 8080
-
Expose the Service with a Route:
apiVersion: route.openshift.io/v1 kind: Route metadata: name: jenkins spec: to: kind: Service name: jenkins port: targetPort: 80
Additional Settings (if needed):
- Custom Load Balancing Algorithms: If you need a specific load balancing strategy (other than the default round-robin), you can configure it in the route or use annotations to modify HAProxy behavior.
- Health Checks: Ensure your Jenkins deployment has proper readiness and liveness probes to manage pod health effectively.
Conclusion
By default, OpenShift handles load balancing and failover for services exposed via routes. No additional settings are required to achieve basic load balancing and failover across replicas. However, for advanced configurations, you may need to tweak the service and route definitions or use annotations.