Last active
February 25, 2023 17:37
-
-
Save haproxytechblog/4d7e6a158766e44cee5b7adb94f0a077 to your computer and use it in GitHub Desktop.
Rolling Updates and Blue-Green Deployments with Kubernetes and HAProxy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: v1 | |
kind: ConfigMap | |
metadata: | |
name: haproxy-configmap | |
namespace: default | |
data: | |
ssl-redirect: "OFF" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: v1 | |
kind: Service | |
metadata: | |
name: app-service | |
spec: | |
selector: | |
run: app | |
ports: | |
- name: http | |
port: 80 | |
protocol: TCP | |
targetPort: 3000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: networking.k8s.io/v1beta1 | |
kind: Ingress | |
metadata: | |
name: app-ingress | |
namespace: default | |
spec: | |
rules: | |
- http: | |
paths: | |
- path: / | |
backend: | |
serviceName: app-service | |
servicePort: 80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ kubectl apply -f app.yaml -f app-service.yaml -f ingress.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
image: errm/versions:0.0.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ kubectl apply -f app.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ kubectl rollout status deployment app | |
deployment "app" successfully rolled out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ kubectl rollout undo deployment app | |
deployment.extensions/app rolled back |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: networking.k8s.io/v1beta1 | |
kind: Ingress | |
metadata: | |
name: app-ingress | |
namespace: default | |
spec: | |
rules: | |
- http: | |
paths: | |
- path: / | |
backend: | |
serviceName: app-service | |
servicePort: 80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ kubectl apply -f app-v1.yaml -f app-service-bg.yaml -f ingress.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ kubectl apply -f app-v2.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ kubectl apply -f app-service.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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