k8s_rollback: new module (#26)

This module allows user to rollback deployment and daemonsets.

Signed-off-by: Julien Huon <julien@huon.email>
This commit is contained in:
Julien Huon
2020-10-07 06:37:47 +02:00
committed by GitHub
parent fc1f4e5ffd
commit 0377a892d5
3 changed files with 442 additions and 0 deletions

View File

@@ -29,6 +29,7 @@
- include_tasks: tasks/log.yml
- include_tasks: tasks/cluster_info.yml
- include_tasks: tasks/access_review.yml
- include_tasks: tasks/rollback.yml
roles:
- helm

View File

@@ -0,0 +1,217 @@
---
- block:
- name: Set variables
set_fact:
namespace: "testingrollback"
- name: Create a namespace
k8s:
name: "{{ namespace }}"
kind: Namespace
api_version: v1
apply: no
register: output
- name: show output
debug:
var: output
- name: Create a deployment
k8s:
state: present
wait: yes
inline: &deploy
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deploy
labels:
app: nginx
namespace: "{{ namespace }}"
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.17
ports:
- containerPort: 80
register: output
- name: Show output
debug:
var: output
- name: Crash the existing deployment
k8s:
state: present
wait: yes
definition:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deploy
labels:
app: nginx
namespace: "{{ namespace }}"
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.0.23449928384992872784
ports:
- containerPort: 80
ignore_errors: yes
register: output
- name: Rolling Back the crashed deployment
k8s_rollback:
api_version: apps/v1
kind: Deployment
name: nginx-deploy
namespace: "{{ namespace }}"
when: output.failed
register: output
- name: Show output
debug:
var: output
- name: Create a DaemonSet
k8s:
state: present
wait: yes
definition:
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: fluentd-elasticsearch
namespace: "{{ namespace }}"
labels:
k8s-app: fluentd-logging
spec:
selector:
matchLabels:
name: fluentd-elasticsearch
template:
metadata:
labels:
name: fluentd-elasticsearch
spec:
tolerations:
- key: node-role.kubernetes.io/master
effect: NoSchedule
containers:
- name: fluentd-elasticsearch
image: quay.io/fluentd_elasticsearch/fluentd:v2.5.2
resources:
limits:
memory: 200Mi
requests:
cpu: 100m
memory: 200Mi
volumeMounts:
- name: varlog
mountPath: /var/log
- name: varlibdockercontainers
mountPath: /var/lib/docker/containers
readOnly: true
terminationGracePeriodSeconds: 30
volumes:
- name: varlog
hostPath:
path: /var/log
- name: varlibdockercontainers
hostPath:
path: /var/lib/docker/containers
register: output
- name: Show output
debug:
var: output
- name: Crash the existing DaemonSet
k8s:
state: present
wait: yes
definition:
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: fluentd-elasticsearch
namespace: "{{ namespace }}"
labels:
k8s-app: fluentd-logging
spec:
selector:
matchLabels:
name: fluentd-elasticsearch
template:
metadata:
labels:
name: fluentd-elasticsearch
spec:
tolerations:
- key: node-role.kubernetes.io/master
effect: NoSchedule
containers:
- name: fluentd-elasticsearch
image: quay.io/fluentd_elasticsearch/fluentd:v2734894949
resources:
limits:
memory: 200Mi
requests:
cpu: 100m
memory: 200Mi
volumeMounts:
- name: varlog
mountPath: /var/log
- name: varlibdockercontainers
mountPath: /var/lib/docker/containers
readOnly: true
terminationGracePeriodSeconds: 30
volumes:
- name: varlog
hostPath:
path: /var/log
- name: varlibdockercontainers
hostPath:
path: /var/lib/docker/containers
ignore_errors: yes
register: output
- name: Rolling Back the crashed DaemonSet
k8s_rollback:
api_version: apps/v1
kind: DaemonSet
name: fluentd-elasticsearch
namespace: "{{ namespace }}"
when: output.failed
register: output
- name: Show output
debug:
var: output
always:
- name: Delete {{ namespace }} namespace
k8s:
name: "{{ namespace }}"
kind: Namespace
api_version: v1
state: absent