Skip to content

Commit b2a219c

Browse files
authored
Merge pull request #14 from okartau/add-inter-pod-affinity
Change example deployment scheme in multi-node cluster
2 parents c44a77d + 5fde450 commit b2a219c

File tree

5 files changed

+57
-4
lines changed

5 files changed

+57
-4
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ rolebinding.rbac.authorization.k8s.io/csi-attacher-role-cfg created
3131
deploying hostpath components
3232
service/csi-hostpath-attacher created
3333
statefulset.apps/csi-hostpath-attacher created
34-
daemonset.apps/csi-hostpathplugin created
34+
statefulset.apps/csi-hostpathplugin created
3535
service/csi-hostpath-provisioner created
3636
statefulset.apps/csi-hostpath-provisioner created
3737
```
@@ -50,7 +50,7 @@ $ kubectl get pods
5050
NAME READY STATUS RESTARTS AGE
5151
csi-hostpath-attacher-0 1/1 Running 0 5m47s
5252
csi-hostpath-provisioner-0 1/1 Running 0 5m47s
53-
csi-hostpathplugin-lzzlc 2/2 Running 0 5m45s
53+
csi-hostpathplugin-0 2/2 Running 0 5m45s
5454
```
5555

5656
From the root directory, deploy the application pods including a storage class, a PVC, and a pod which mounts a volume using the Hostpath driver found in directory `./examples`:

deploy/hostpath/csi-hostpath-attacher.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ spec:
2727
labels:
2828
app: csi-hostpath-attacher
2929
spec:
30+
affinity:
31+
podAffinity:
32+
requiredDuringSchedulingIgnoredDuringExecution:
33+
- labelSelector:
34+
matchExpressions:
35+
- key: app
36+
operator: In
37+
values:
38+
- csi-hostpathplugin
39+
topologyKey: kubernetes.io/hostname
3040
serviceAccountName: csi-attacher
3141
containers:
3242
- name: csi-attacher

deploy/hostpath/csi-hostpath-plugin.yaml

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,31 @@
1-
kind: DaemonSet
1+
# Service defined here, plus serviceName below in StatefulSet,
2+
# are needed only because of condition explained in
3+
# https://github.com/kubernetes/kubernetes/issues/69608
4+
5+
kind: Service
6+
apiVersion: v1
7+
metadata:
8+
name: csi-hostpathplugin
9+
labels:
10+
app: csi-hostpathplugin
11+
spec:
12+
selector:
13+
app: csi-hostpathplugin
14+
ports:
15+
- name: dummy
16+
port: 12345
17+
---
18+
kind: StatefulSet
219
apiVersion: apps/v1
320
metadata:
421
name: csi-hostpathplugin
522
spec:
23+
serviceName: "csi-hostpathplugin"
24+
# One replica only:
25+
# Host path driver only works when everything runs
26+
# on a single node. We achieve that by starting it once and then
27+
# co-locate all other pods via inter-pod affinity
28+
replicas: 1
629
selector:
730
matchLabels:
831
app: csi-hostpathplugin

deploy/hostpath/csi-hostpath-provisioner.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ spec:
2727
labels:
2828
app: csi-hostpath-provisioner
2929
spec:
30+
affinity:
31+
podAffinity:
32+
requiredDuringSchedulingIgnoredDuringExecution:
33+
- labelSelector:
34+
matchExpressions:
35+
- key: app
36+
operator: In
37+
values:
38+
- csi-hostpathplugin
39+
topologyKey: kubernetes.io/hostname
3040
serviceAccountName: csi-provisioner
3141
containers:
3242
- name: csi-provisioner

examples/csi-app.yaml

+11-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ apiVersion: v1
33
metadata:
44
name: my-csi-app
55
spec:
6+
affinity:
7+
podAffinity:
8+
requiredDuringSchedulingIgnoredDuringExecution:
9+
- labelSelector:
10+
matchExpressions:
11+
- key: app
12+
operator: In
13+
values:
14+
- csi-hostpathplugin
15+
topologyKey: kubernetes.io/hostname
616
containers:
717
- name: my-frontend
818
image: busybox
@@ -13,4 +23,4 @@ spec:
1323
volumes:
1424
- name: my-csi-volume
1525
persistentVolumeClaim:
16-
claimName: csi-pvc # defined in csi-pvs.yaml
26+
claimName: csi-pvc # defined in csi-pvs.yaml

0 commit comments

Comments
 (0)