Skip to content

Commit 1955c7d

Browse files
committed
deploy: preliminary example for Kubernetes 1.14
The only difference is in the image versions. We still need two examples, because some CSI driver developers may need the older example for Kubernetes 1.13 if they depend on the alpha features. It's preliminary because the actual images haven't been released yet.
1 parent 196f8b0 commit 1955c7d

9 files changed

+509
-6
lines changed

deploy/kubernetes-1.13/README.md

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
The deployment for Kubernetes 1.13 uses CSI 1.0 and this is
1+
The deployment for Kubernetes 1.13 uses CSI 1.0 and thus is
22
incompatible with older Kubernetes releases.
33

4-
It relies on the CRDs for CSIDriverInfo and CSINodeInfo, which are
5-
about to be replaced with builtin APIs in Kubernetes 1.14. It can be
4+
The sidecar images rely on the CRDs for CSIDriverInfo and CSINodeInfo,
5+
which were replaced with builtin APIs in Kubernetes 1.14. They can be
66
deployed on Kubernetes 1.14 if the CRDs are installed, but features
77
relying on these CRDs (like topology) are unlikely to work.
8-
9-
Kubernetes 1.14 will need a different deployment.

deploy/kubernetes-1.14/README.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
The deployment for Kubernetes 1.14 uses CSI 1.0 and thus is incompatible with
2+
Kubernetes < 1.13.
3+
4+
It uses the builtin APIs for CSIDriverInfo and CSINodeInfo that were
5+
introduced in Kubernetes 1.14, so features depending on those (like
6+
topology) will not work on Kubernetes 1.13. But because this example
7+
deployment does not enable those features, it can run on Kubernetes 1.13.
8+
9+
WARNING: the images for Kubernetes 1.14 have not been released yet, so this
10+
example uses the "canary" images instead.
+138
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
#!/usr/bin/env bash
2+
3+
# This script captures the steps required to successfully
4+
# deploy the hostpath plugin driver. This should be considered
5+
# authoritative and all updates for this process should be
6+
# done here and referenced elsewhere.
7+
8+
# The script assumes that kubectl is available on the OS path
9+
# where it is executed.
10+
11+
set -e
12+
set -o pipefail
13+
14+
BASE_DIR=$(dirname "$0")
15+
K8S_RELEASE=${K8S_RELEASE:-"release-1.13"}
16+
17+
# If set, the following env variables override image registry and/or tag for each of the images.
18+
# They are named after the image name, with hyphen replaced by underscore and in upper case.
19+
#
20+
# - CSI_ATTACHER_REGISTRY
21+
# - CSI_ATTACHER_TAG
22+
# - CSI_NODE_DRIVER_REGISTRAR_REGISTRY
23+
# - CSI_NODE_DRIVER_REGISTRAR_TAG
24+
# - CSI_PROVISIONER_REGISTRY
25+
# - CSI_PROVISIONER_TAG
26+
# - CSI_SNAPSHOTTER_REGISTRY
27+
# - CSI_SNAPSHOTTER_TAG
28+
# - HOSTPATHPLUGIN_REGISTRY
29+
# - HOSTPATHPLUGIN_TAG
30+
#
31+
# Alternatively, it is possible to override all registries or tags with:
32+
# - IMAGE_REGISTRY
33+
# - IMAGE_TAG
34+
# These are used as fallback when the more specific variables are unset or empty.
35+
#
36+
# Beware that the .yaml files do not have "imagePullPolicy: Always". That means that
37+
# also the "canary" images will only be pulled once. This is good for testing
38+
# (starting a pod multiple times will always run with the same canary image), but
39+
# implies that refreshing that image has to be done manually.
40+
#
41+
# As a special case, 'none' as registry removes the registry name.
42+
43+
function image_version () {
44+
yaml="$1"
45+
image="$2"
46+
47+
# get version from `image: quay.io/k8scsi/csi-attacher:v1.0.1`
48+
version="$(grep "image:.*$image" "$yaml" | sed -e 's/.*:v/v/')"
49+
50+
# apply overrides
51+
varname=$(echo $image | tr - _ | tr a-z A-Z)
52+
eval version=\${${varname}_TAG:-\${IMAGE_TAG:-\$version}}
53+
54+
# When using canary images, we have to assume that the
55+
# canary images were built from the corresponding branch.
56+
case "$version" in canary) version=master;;
57+
*-canary) version="$(echo "$version" | sed -e 's/\(.*\)-canary/release-\1/')";;
58+
esac
59+
echo "$version"
60+
}
61+
62+
# In addition, the RBAC rules can be overridden for provisioner and attacher.
63+
CSI_PROVISIONER_RBAC=${PROVISIONER_RBAC:-https://raw.githubusercontent.com/kubernetes-csi/external-provisioner/$(image_version "${BASE_DIR}/hostpath/csi-hostpath-provisioner.yaml" csi-provisioner)/deploy/kubernetes/rbac.yaml}
64+
CSI_ATTACHER_RBAC=${ATTACHER_RBAC:-https://raw.githubusercontent.com/kubernetes-csi/external-attacher/$(image_version "${BASE_DIR}/hostpath/csi-hostpath-attacher.yaml" csi-attacher)/deploy/kubernetes/rbac.yaml}
65+
CSI_SNAPSHOTTER_RBAC=${CSI_SNAPSHOTTER_RBAC:-https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/$(image_version "${BASE_DIR}/hostpath/csi-hostpath-snapshotter.yaml" csi-snapshotter)/deploy/kubernetes/rbac.yaml}
66+
67+
INSTALL_CRD=${INSTALL_CRD:-"false"}
68+
69+
run () {
70+
echo "$@" >&2
71+
"$@"
72+
}
73+
74+
# apply CSIDriver and CSINodeInfo API objects
75+
if [[ "${INSTALL_CRD}" =~ ^(y|Y|yes|true)$ ]] ; then
76+
echo "installing CRDs"
77+
run kubectl apply -f https://raw.githubusercontent.com/kubernetes/csi-api/${K8S_RELEASE}/pkg/crd/manifests/csidriver.yaml --validate=false
78+
run kubectl apply -f https://raw.githubusercontent.com/kubernetes/csi-api/${K8S_RELEASE}/pkg/crd/manifests/csinodeinfo.yaml --validate=false
79+
fi
80+
81+
# rbac rules
82+
echo "applying RBAC rules"
83+
run kubectl apply -f "${CSI_PROVISIONER_RBAC}"
84+
run kubectl apply -f "${CSI_ATTACHER_RBAC}"
85+
run kubectl apply -f "${CSI_SNAPSHOTTER_RBAC}"
86+
87+
# deploy hostpath plugin and registrar sidecar
88+
echo "deploying hostpath components"
89+
for i in ${BASE_DIR}/hostpath/*.yaml; do
90+
echo " $i"
91+
modified="$(cat "$i" | while IFS= read -r line; do
92+
if echo "$line" | grep -q '^\s*image:\s*'; then
93+
# Split 'image: quay.io/k8scsi/csi-attacher:v1.0.1'
94+
# into image (quay.io/k8scsi/csi-attacher:v1.0.1),
95+
# registry (quay.io/k8scsi),
96+
# name (csi-attacher),
97+
# tag (v1.0.1).
98+
image=$(echo "$line" | sed -e 's;.*image:\s*;;')
99+
registry=$(echo "$image" | sed -e 's;\(.*\)/.*;\1;')
100+
name=$(echo "$image" | sed -e 's;.*/\([^:]*\).*;\1;')
101+
tag=$(echo "$image" | sed -e 's;.*:;;')
102+
103+
# Variables are with underscores and upper case.
104+
varname=$(echo $name | tr - _ | tr a-z A-Z)
105+
106+
# Now replace registry and/or tag, if set as env variables.
107+
# If not set, the replacement is the same as the original value.
108+
prefix=$(eval echo \${${varname}_REGISTRY:-${IMAGE_REGISTRY:-${registry}}}/ | sed -e 's;none/;;')
109+
suffix=$(eval echo :\${${varname}_TAG:-${IMAGE_TAG:-${tag}}})
110+
line="$(echo "$line" | sed -e "s;$image;${prefix}${name}${suffix};")"
111+
echo " using $line" >&2
112+
fi
113+
echo "$line"
114+
done)"
115+
if ! echo "$modified" | kubectl apply -f -; then
116+
echo "modified version of $i:"
117+
echo "$modified"
118+
exit 1
119+
fi
120+
done
121+
122+
# Wait until all pods are running. We have to make some assumptions
123+
# about the deployment here, otherwise we wouldn't know what to wait
124+
# for: the expectation is that we run attacher, provisioner,
125+
# snapshotter, socat and hostpath plugin in the default namespace.
126+
cnt=0
127+
while [ $(kubectl get pods 2>/dev/null | grep '^csi-hostpath.* Running ' | wc -l) -lt 5 ]; do
128+
if [ $cnt -gt 30 ]; then
129+
echo "Running pods:"
130+
kubectl describe pods
131+
132+
echo >&2 "ERROR: hostpath deployment not ready after over 5min"
133+
exit 1
134+
fi
135+
echo $(date +%H:%M:%S) "waiting for hostpath deployment to complete, attempt #$cnt"
136+
cnt=$(($cnt + 1))
137+
sleep 10
138+
done
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
kind: Service
2+
apiVersion: v1
3+
metadata:
4+
name: csi-hostpath-attacher
5+
labels:
6+
app: csi-hostpath-attacher
7+
spec:
8+
selector:
9+
app: csi-hostpath-attacher
10+
ports:
11+
- name: dummy
12+
port: 12345
13+
14+
---
15+
kind: StatefulSet
16+
apiVersion: apps/v1
17+
metadata:
18+
name: csi-hostpath-attacher
19+
spec:
20+
serviceName: "csi-hostpath-attacher"
21+
replicas: 1
22+
selector:
23+
matchLabels:
24+
app: csi-hostpath-attacher
25+
template:
26+
metadata:
27+
labels:
28+
app: csi-hostpath-attacher
29+
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
40+
serviceAccountName: csi-attacher
41+
containers:
42+
- name: csi-attacher
43+
image: quay.io/k8scsi/csi-attacher:canary # TODO: replace with released version
44+
args:
45+
- --v=5
46+
- --csi-address=/csi/csi.sock
47+
volumeMounts:
48+
- mountPath: /csi
49+
name: socket-dir
50+
51+
volumes:
52+
- hostPath:
53+
path: /var/lib/kubelet/plugins/csi-hostpath
54+
type: DirectoryOrCreate
55+
name: socket-dir
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
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
19+
apiVersion: apps/v1
20+
metadata:
21+
name: csi-hostpathplugin
22+
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
29+
selector:
30+
matchLabels:
31+
app: csi-hostpathplugin
32+
template:
33+
metadata:
34+
labels:
35+
app: csi-hostpathplugin
36+
spec:
37+
hostNetwork: true
38+
containers:
39+
- name: node-driver-registrar
40+
image: quay.io/k8scsi/csi-node-driver-registrar:canary # TODO: replace with released version
41+
lifecycle:
42+
preStop:
43+
exec:
44+
command: ["/bin/sh", "-c", "rm -rf /registration/csi-hostpath /registration/csi-hostpath-reg.sock"]
45+
args:
46+
- --v=5
47+
- --csi-address=/csi/csi.sock
48+
- --kubelet-registration-path=/var/lib/kubelet/plugins/csi-hostpath/csi.sock
49+
securityContext:
50+
privileged: true
51+
env:
52+
- name: KUBE_NODE_NAME
53+
valueFrom:
54+
fieldRef:
55+
apiVersion: v1
56+
fieldPath: spec.nodeName
57+
volumeMounts:
58+
- mountPath: /csi
59+
name: socket-dir
60+
- mountPath: /registration
61+
name: registration-dir
62+
- mountPath: /csi-data-dir
63+
name: csi-data-dir
64+
65+
- name: hostpath
66+
image: quay.io/k8scsi/hostpathplugin:canary # TODO: replace with released version
67+
args:
68+
- "--v=5"
69+
- "--endpoint=$(CSI_ENDPOINT)"
70+
- "--nodeid=$(KUBE_NODE_NAME)"
71+
env:
72+
- name: CSI_ENDPOINT
73+
value: unix:///csi/csi.sock
74+
- name: KUBE_NODE_NAME
75+
valueFrom:
76+
fieldRef:
77+
apiVersion: v1
78+
fieldPath: spec.nodeName
79+
securityContext:
80+
privileged: true
81+
ports:
82+
- containerPort: 9898
83+
name: healthz
84+
protocol: TCP
85+
livenessProbe:
86+
failureThreshold: 5
87+
httpGet:
88+
path: /healthz
89+
port: healthz
90+
initialDelaySeconds: 10
91+
timeoutSeconds: 3
92+
periodSeconds: 2
93+
volumeMounts:
94+
- mountPath: /csi
95+
name: socket-dir
96+
- mountPath: /var/lib/kubelet/pods
97+
mountPropagation: Bidirectional
98+
name: mountpoint-dir
99+
- mountPath: /var/lib/kubelet/plugins
100+
mountPropagation: Bidirectional
101+
name: plugins-dir
102+
103+
- name: liveness-probe
104+
imagePullPolicy: Always
105+
volumeMounts:
106+
- mountPath: /csi
107+
name: socket-dir
108+
image: quay.io/k8scsi/livenessprobe:v1.0.2
109+
args:
110+
- --csi-address=/csi/csi.sock
111+
- --connection-timeout=3s
112+
- --health-port=9898
113+
114+
volumes:
115+
- hostPath:
116+
path: /var/lib/kubelet/plugins/csi-hostpath
117+
type: DirectoryOrCreate
118+
name: socket-dir
119+
- hostPath:
120+
path: /var/lib/kubelet/pods
121+
type: DirectoryOrCreate
122+
name: mountpoint-dir
123+
- hostPath:
124+
path: /var/lib/kubelet/plugins_registry
125+
type: Directory
126+
name: registration-dir
127+
- hostPath:
128+
path: /var/lib/kubelet/plugins
129+
type: Directory
130+
name: plugins-dir
131+
- hostPath:
132+
# 'path' is where PV data is persisted on host.
133+
# using /tmp is also possible while the PVs will not available after plugin container recreation or host reboot
134+
path: /var/lib/csi-hostpath-data/
135+
type: DirectoryOrCreate
136+
name: csi-data-dir

0 commit comments

Comments
 (0)