Skip to content

Commit 879ba77

Browse files
committed
deploy: preliminary example for master and Kubernetes 1.14
The only difference compared to kubernetes-1.13 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 for Kubernetes 1.14 because the actual images haven't been released yet.
1 parent 41522f4 commit 879ba77

13 files changed

+560
-15
lines changed

README.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ This repository hosts the CSI Hostpath driver and all of its build and dependent
88
- Access to terminal with `kubectl` installed
99

1010
## Deployment
11-
The easiest way to test the Hostpath driver is to run `deploy/deploy-hostpath.sh` script as shown:
11+
The easiest way to test the Hostpath driver is to run the `deploy-hostpath.sh` script for the Kubernetes version used by
12+
the cluster as shown below for Kubernetes 1.13. This creates the deployment that is maintained specifically for that
13+
release of Kubernetes. However, other deployments may also work. For details see the individual READMEs.
1214

1315
```shell
14-
$ deploy/deploy-hostpath.sh
16+
$ deploy/kubernetes-1.13/deploy-hostpath.sh
1517
```
1618

1719
You should see an output similar to the following printed on the terminal showing the application of rbac rules and the result of deploying the hostpath driver, external provisioner, external attacher and snapshotter components:
@@ -35,27 +37,29 @@ serviceaccount/csi-snapshotter created
3537
clusterrole.rbac.authorization.k8s.io/external-snapshotter-runner created
3638
clusterrolebinding.rbac.authorization.k8s.io/csi-snapshotter-role created
3739
deploying hostpath components
38-
deploy/hostpath/csi-hostpath-attacher.yaml
40+
deploy/kubernetes-1.13/hostpath/csi-hostpath-attacher.yaml
3941
using image: quay.io/k8scsi/csi-attacher:v1.0.1
4042
service/csi-hostpath-attacher created
4143
statefulset.apps/csi-hostpath-attacher created
42-
deploy/hostpath/csi-hostpath-plugin.yaml
44+
deploy/kubernetes-1.13/hostpath/csi-hostpath-plugin.yaml
4345
using image: quay.io/k8scsi/csi-node-driver-registrar:v1.0.2
4446
using image: quay.io/k8scsi/hostpathplugin:v1.0.1
4547
using image: quay.io/k8scsi/livenessprobe:v1.0.2
4648
service/csi-hostpathplugin created
4749
statefulset.apps/csi-hostpathplugin created
48-
deploy/hostpath/csi-hostpath-provisioner.yaml
50+
deploy/kubernetes-1.13/hostpath/csi-hostpath-provisioner.yaml
4951
using image: quay.io/k8scsi/csi-provisioner:v1.0.1
5052
service/csi-hostpath-provisioner created
5153
statefulset.apps/csi-hostpath-provisioner created
52-
deploy/hostpath/csi-hostpath-snapshotter.yaml
54+
deploy/kubernetes-1.13/hostpath/csi-hostpath-snapshotter.yaml
5355
using image: quay.io/k8scsi/csi-snapshotter:v1.0.1
5456
service/csi-hostpath-snapshotter created
5557
statefulset.apps/csi-hostpath-snapshotter created
56-
23:04:27 waiting for hostpath deployment to complete, attempt #0
57-
23:04:38 waiting for hostpath deployment to complete, attempt #1
58-
23:04:48 waiting for hostpath deployment to complete, attempt #2
58+
deploy/kubernetes-1.13/hostpath/csi-hostpath-testing.yaml
59+
using image: alpine/socat:1.0.3
60+
service/hostpath-service created
61+
statefulset.apps/csi-hostpath-socat created
62+
23:16:10 waiting for hostpath deployment to complete, attempt #0
5963
deploying snapshotclass
6064
volumesnapshotclass.snapshot.storage.k8s.io/csi-hostpath-snapclass created
6165
```

deploy/kubernetes-1.13/README.md

Lines changed: 3 additions & 5 deletions
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/snapshotter/csi-hostpath-snapshotclass.yaml renamed to deploy/kubernetes-1.13/snapshotter/csi-hostpath-snapshotclass.yaml

File renamed without changes.

deploy/kubernetes-1.14

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
master

deploy/kubernetes-latest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
kubernetes-1.13
1+
kubernetes-1.14

deploy/master/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
The deployment for master uses CSI 1.0 and thus is incompatible with
2+
Kubernetes < 1.13.
3+
4+
It uses the 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
8+
1.13.
9+
10+
WARNING: this example uses the "canary" images. It can break at any
11+
time.

deploy/master/deploy-hostpath.sh

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
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+
# The default is to use the RBAC rules that match the image that is
44+
# being used, also in the case that the image gets overridden. This
45+
# way if there are breaking changes in the RBAC rules, the deployment
46+
# will continue to work.
47+
#
48+
# However, such breaking changes should be rare and only occur when updating
49+
# to a new major version of a sidecar. Nonetheless, to allow testing the scenario
50+
# where the image gets overridden but not the RBAC rules, updating the RBAC
51+
# rules can be disabled.
52+
: ${UPDATE_RBAC_RULES:=true}
53+
function rbac_version () {
54+
yaml="$1"
55+
image="$2"
56+
update_rbac="$3"
57+
58+
# get version from `image: quay.io/k8scsi/csi-attacher:v1.0.1`, ignoring comments
59+
version="$(sed -e 's/ *#.*$//' "$yaml" | grep "image:.*$image" | sed -e 's/ *#.*//' -e 's/.*://')"
60+
61+
if $update_rbac; then
62+
# apply overrides
63+
varname=$(echo $image | tr - _ | tr a-z A-Z)
64+
eval version=\${${varname}_TAG:-\${IMAGE_TAG:-\$version}}
65+
fi
66+
67+
# When using canary images, we have to assume that the
68+
# canary images were built from the corresponding branch.
69+
case "$version" in canary) version=master;;
70+
*-canary) version="$(echo "$version" | sed -e 's/\(.*\)-canary/release-\1/')";;
71+
esac
72+
73+
echo "$version"
74+
}
75+
76+
# In addition, the RBAC rules can be overridden separately.
77+
CSI_PROVISIONER_RBAC_YAML="https://raw.githubusercontent.com/kubernetes-csi/external-provisioner/$(rbac_version "${BASE_DIR}/hostpath/csi-hostpath-provisioner.yaml" csi-provisioner false)/deploy/kubernetes/rbac.yaml"
78+
: ${CSI_PROVISIONER_RBAC:=https://raw.githubusercontent.com/kubernetes-csi/external-provisioner/$(rbac_version "${BASE_DIR}/hostpath/csi-hostpath-provisioner.yaml" csi-provisioner "${UPDATE_RBAC_RULES}")/deploy/kubernetes/rbac.yaml}
79+
CSI_ATTACHER_RBAC_YAML="https://raw.githubusercontent.com/kubernetes-csi/external-attacher/$(rbac_version "${BASE_DIR}/hostpath/csi-hostpath-attacher.yaml" csi-attacher false)/deploy/kubernetes/rbac.yaml"
80+
: ${CSI_ATTACHER_RBAC:=https://raw.githubusercontent.com/kubernetes-csi/external-attacher/$(rbac_version "${BASE_DIR}/hostpath/csi-hostpath-attacher.yaml" csi-attacher "${UPDATE_RBAC_RULES}")/deploy/kubernetes/rbac.yaml}
81+
CSI_SNAPSHOTTER_RBAC_YAML="https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/$(rbac_version "${BASE_DIR}/hostpath/csi-hostpath-snapshotter.yaml" csi-snapshotter false)/deploy/kubernetes/rbac.yaml"
82+
: ${CSI_SNAPSHOTTER_RBAC:=https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/$(rbac_version "${BASE_DIR}/hostpath/csi-hostpath-snapshotter.yaml" csi-snapshotter "${UPDATE_RBAC_RULES}")/deploy/kubernetes/rbac.yaml}
83+
84+
INSTALL_CRD=${INSTALL_CRD:-"false"}
85+
86+
run () {
87+
echo "$@" >&2
88+
"$@"
89+
}
90+
91+
# apply CSIDriver and CSINodeInfo API objects
92+
if [[ "${INSTALL_CRD}" =~ ^(y|Y|yes|true)$ ]] ; then
93+
echo "installing CRDs"
94+
run kubectl apply -f https://raw.githubusercontent.com/kubernetes/csi-api/${K8S_RELEASE}/pkg/crd/manifests/csidriver.yaml --validate=false
95+
run kubectl apply -f https://raw.githubusercontent.com/kubernetes/csi-api/${K8S_RELEASE}/pkg/crd/manifests/csinodeinfo.yaml --validate=false
96+
fi
97+
98+
# rbac rules
99+
echo "applying RBAC rules"
100+
for component in CSI_PROVISIONER CSI_ATTACHER CSI_SNAPSHOTTER; do
101+
eval current="\${${component}_RBAC}"
102+
eval original="\${${component}_RBAC_YAML}"
103+
if [ "$current" != "$original" ]; then
104+
echo "Using non-default RBAC rules for $component. Changes from $original to $current are:"
105+
diff -c <(wget --quiet -O - "$original") <(if [[ "$current" =~ ^http ]]; then wget --quiet -O - "$current"; else cat "$current"; fi) || true
106+
fi
107+
run kubectl apply -f "${current}"
108+
done
109+
110+
# deploy hostpath plugin and registrar sidecar
111+
echo "deploying hostpath components"
112+
for i in $(ls ${BASE_DIR}/hostpath/*.yaml | sort); do
113+
echo " $i"
114+
modified="$(cat "$i" | while IFS= read -r line; do
115+
nocomments="$(echo "$line" | sed -e 's/ *#.*$//')"
116+
if echo "$nocomments" | grep -q '^\s*image:\s*'; then
117+
# Split 'image: quay.io/k8scsi/csi-attacher:v1.0.1'
118+
# into image (quay.io/k8scsi/csi-attacher:v1.0.1),
119+
# registry (quay.io/k8scsi),
120+
# name (csi-attacher),
121+
# tag (v1.0.1).
122+
image=$(echo "$nocomments" | sed -e 's;.*image:\s*;;')
123+
registry=$(echo "$image" | sed -e 's;\(.*\)/.*;\1;')
124+
name=$(echo "$image" | sed -e 's;.*/\([^:]*\).*;\1;')
125+
tag=$(echo "$image" | sed -e 's;.*:;;')
126+
127+
# Variables are with underscores and upper case.
128+
varname=$(echo $name | tr - _ | tr a-z A-Z)
129+
130+
# Now replace registry and/or tag, if set as env variables.
131+
# If not set, the replacement is the same as the original value.
132+
prefix=$(eval echo \${${varname}_REGISTRY:-${IMAGE_REGISTRY:-${registry}}}/ | sed -e 's;none/;;')
133+
suffix=$(eval echo :\${${varname}_TAG:-${IMAGE_TAG:-${tag}}})
134+
line="$(echo "$nocomments" | sed -e "s;$image;${prefix}${name}${suffix};")"
135+
echo " using $line" >&2
136+
fi
137+
echo "$line"
138+
done)"
139+
if ! echo "$modified" | kubectl apply -f -; then
140+
echo "modified version of $i:"
141+
echo "$modified"
142+
exit 1
143+
fi
144+
done
145+
146+
# Wait until all pods are running. We have to make some assumptions
147+
# about the deployment here, otherwise we wouldn't know what to wait
148+
# for: the expectation is that we run attacher, provisioner,
149+
# snapshotter, socat and hostpath plugin in the default namespace.
150+
cnt=0
151+
while [ $(kubectl get pods 2>/dev/null | grep '^csi-hostpath.* Running ' | wc -l) -lt 5 ] || ! kubectl describe volumesnapshotclasses.snapshot.storage.k8s.io 2>/dev/null >/dev/null; do
152+
if [ $cnt -gt 30 ]; then
153+
echo "Running pods:"
154+
kubectl describe pods
155+
156+
echo >&2 "ERROR: hostpath deployment not ready after over 5min"
157+
exit 1
158+
fi
159+
echo $(date +%H:%M:%S) "waiting for hostpath deployment to complete, attempt #$cnt"
160+
cnt=$(($cnt + 1))
161+
sleep 10
162+
done
163+
164+
# deploy snapshotclass
165+
echo "deploying snapshotclass"
166+
kubectl create -f ${BASE_DIR}/snapshotter/csi-hostpath-snapshotclass.yaml
Lines changed: 55 additions & 0 deletions
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

0 commit comments

Comments
 (0)