Skip to content

Instantly share code, notes, and snippets.

@haproxytechblog
Last active February 25, 2023 17:37
Show Gist options
  • Save haproxytechblog/4d7e6a158766e44cee5b7adb94f0a077 to your computer and use it in GitHub Desktop.
Save haproxytechblog/4d7e6a158766e44cee5b7adb94f0a077 to your computer and use it in GitHub Desktop.
Rolling Updates and Blue-Green Deployments with Kubernetes and HAProxy
apiVersion: v1
kind: ConfigMap
metadata:
name: haproxy-configmap
namespace: default
data:
ssl-redirect: "OFF"
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
run: app
name: app
spec:
replicas: 5
selector:
matchLabels:
run: app
template:
metadata:
labels:
run: app
spec:
containers:
- name: app
image: errm/versions:0.0.1
ports:
- containerPort: 3000
readinessProbe:
httpGet:
path: /
port: 3000
initialDelaySeconds: 5
periodSeconds: 5
successThreshold: 1
apiVersion: v1
kind: Service
metadata:
name: app-service
spec:
selector:
run: app
ports:
- name: http
port: 80
protocol: TCP
targetPort: 3000
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: app-ingress
namespace: default
spec:
rules:
- http:
paths:
- path: /
backend:
serviceName: app-service
servicePort: 80
$ kubectl apply -f app.yaml -f app-service.yaml -f ingress.yaml
$ kubectl get svc haproxy-ingress -n haproxy-controller
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
haproxy-ingress NodePort 10.101.75.28 <none> 80:31179/TCP,443:31923/TCP,1024:30430/TCP 98s
image: errm/versions:0.0.2
$ kubectl apply -f app.yaml
$ kubectl rollout status deployment app
deployment "app" successfully rolled out
$ kubectl rollout undo deployment app
deployment.extensions/app rolled back
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
run: app
name: app-blue
spec:
replicas: 1
selector:
matchLabels:
run: app
version: 0.0.1
template:
metadata:
labels:
run: app
version: 0.0.1
spec:
containers:
- name: app
image: errm/versions:0.0.1
ports:
- containerPort: 3000
apiVersion: v1
kind: Service
metadata:
name: app-service
spec:
selector:
run: app
version: 0.0.1
ports:
- name: http
port: 80
protocol: TCP
targetPort: 3000
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: app-ingress
namespace: default
spec:
rules:
- http:
paths:
- path: /
backend:
serviceName: app-service
servicePort: 80
$ kubectl apply -f app-v1.yaml -f app-service-bg.yaml -f ingress.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
run: app
name: app-green
spec:
replicas: 1
selector:
matchLabels:
run: app
version: 0.0.2
template:
metadata:
labels:
run: app
version: 0.0.2
spec:
containers:
- name: app
image: errm/versions:0.0.2
ports:
- containerPort: 3000
$ kubectl apply -f app-v2.yaml
apiVersion: v1
kind: Service
metadata:
name: app-service
spec:
selector:
run: app
version: 0.0.2
ports:
- name: http
port: 80
protocol: TCP
targetPort: 3000
$ kubectl apply -f app-service.yaml
apiVersion: v1
kind: Service
metadata:
name: test-service
annotations:
haproxy.org/path-rewrite: /
spec:
selector:
run: app
version: 0.0.2
ports:
- name: http
port: 80
protocol: TCP
targetPort: 3000
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: app-ingress
namespace: default
annotations:
haproxy.org/ingress.class: "development"
spec:
rules:
- http:
paths:
- path: /
backend:
serviceName: app-service
servicePort: 80
- path: /test
backend:
serviceName: test-service
servicePort: 80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment