forked from ansible-collections/community.kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
k8s_rollback: new module (ansible-collections#26)
This module allows user to rollback deployment and daemonsets. Signed-off-by: Julien Huon <julien@huon.email>
- Loading branch information
1 parent
fc1f4e5
commit 0377a89
Showing
3 changed files
with
442 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.