Skip to content

Commit 18e5a99

Browse files
adding pod affinity code
1 parent 538ed7a commit 18e5a99

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-0
lines changed

playbooks/pod-affinity-test.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
- name: Run pod affinity and pause pod test
3+
hosts: bastion
4+
roles:
5+
- pod-affinity-test

playbooks/roles/pod-affinity-test/defaults/main.yml

Whitespace-only changes.
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
---
2+
- name: Create PPC pod with affinity
3+
kubernetes.core.k8s:
4+
state: present
5+
definition:
6+
apiVersion: v1
7+
kind: Pod
8+
metadata:
9+
name: ppc-pod
10+
namespace: default
11+
spec:
12+
affinity:
13+
nodeAffinity:
14+
preferredDuringSchedulingIgnoredDuringExecution:
15+
- weight: 70
16+
preference:
17+
matchExpressions:
18+
- key: kubernetes.io/arch
19+
operator: In
20+
values:
21+
- ppc64le
22+
- weight: 30
23+
preference:
24+
matchExpressions:
25+
- key: kubernetes.io/arch
26+
operator: NotIn
27+
values:
28+
- ppc64le
29+
containers:
30+
- name: web
31+
image: registry.redhat.io/ubi8/pause
32+
33+
- name: Create x86 pod with anti-affinity
34+
kubernetes.core.k8s:
35+
state: present
36+
definition:
37+
apiVersion: v1
38+
kind: Pod
39+
metadata:
40+
name: x86-pod
41+
namespace: default
42+
spec:
43+
affinity:
44+
nodeAffinity:
45+
preferredDuringSchedulingIgnoredDuringExecution:
46+
- weight: 30
47+
preference:
48+
matchExpressions:
49+
- key: kubernetes.io/arch
50+
operator: In
51+
values:
52+
- ppc64le
53+
- weight: 70
54+
preference:
55+
matchExpressions:
56+
- key: kubernetes.io/arch
57+
operator: NotIn
58+
values:
59+
- ppc64le
60+
containers:
61+
- name: web
62+
image: registry.redhat.io/ubi8/pause
63+
64+
- name: Wait until pods are running
65+
command: oc get pods -n default --no-headers
66+
register: pod_status
67+
until: "'Running' in pod_status.stdout"
68+
retries: 10
69+
delay: 10
70+
71+
- name: Launch multiple pause pods
72+
shell: |
73+
for n in $(seq 1 60); do
74+
oc run pause-pod-$n --image=ubi8/pause:8.8-9 -n default
75+
done
76+
77+
- name: Verify all pods running
78+
command: oc get pods -n default -o wide
79+
register: pause_pod_status
80+
changed_when: false
81+
82+
- debug:
83+
msg: "{{ pause_pod_status.stdout_lines }}"
84+
85+
- name: Cleanup - delete all pods
86+
command: oc delete pods --all -n default

0 commit comments

Comments
 (0)