Skip to content

Commit

Permalink
deploy: expose csi.sock outside of the cluster
Browse files Browse the repository at this point in the history
Tools like csi-sanity and csc have to connect to the CSI driver. This
can be achieved by exposing the csi.sock as a TCP service with
forwarding handled by socat.
  • Loading branch information
pohly committed Mar 28, 2019
1 parent 092e8c5 commit 196f8b0
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
4 changes: 2 additions & 2 deletions deploy/kubernetes-1.13/deploy-hostpath.sh
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ done
# Wait until all pods are running. We have to make some assumptions
# about the deployment here, otherwise we wouldn't know what to wait
# for: the expectation is that we run attacher, provisioner,
# snapshotter and hostpath plugin in the default namespace.
# snapshotter, socat and hostpath plugin in the default namespace.
cnt=0
while [ $(kubectl get pods 2>/dev/null | grep '^csi-hostpath.* Running ' | wc -l) -lt 4 ]; do
while [ $(kubectl get pods 2>/dev/null | grep '^csi-hostpath.* Running ' | wc -l) -lt 5 ]; do
if [ $cnt -gt 30 ]; then
echo "Running pods:"
kubectl describe pods
Expand Down
56 changes: 56 additions & 0 deletions deploy/kubernetes-1.13/hostpath/csi-hostpath-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# This exposes the hostpath's Unix domain csi.sock as a TCP port to the
# outside world. The mapping from Unix domain socket to TCP is done
# by socat.
#
# This is useful for testing with csi-sanity or csc.

apiVersion: v1
kind: Service
metadata:
name: hostpath-service
spec:
type: NodePort
selector:
app: csi-hostpath-socat
ports:
- port: 10000 # fixed port inside the pod, dynamically allocated port outside
---
kind: StatefulSet
apiVersion: apps/v1
metadata:
name: csi-hostpath-socat
spec:
serviceName: "csi-hostpath-socat"
replicas: 1
selector:
matchLabels:
app: csi-hostpath-socat
template:
metadata:
labels:
app: csi-hostpath-socat
spec:
affinity:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- csi-hostpathplugin
topologyKey: kubernetes.io/hostname
containers:
- name: socat
image: alpine/socat:1.0.3
args:
- tcp-listen:10000,fork,reuseaddr
- unix-connect:/csi/csi.sock
volumeMounts:
- mountPath: /csi
name: socket-dir
volumes:
- hostPath:
path: /var/lib/kubelet/plugins/csi-hostpath
type: DirectoryOrCreate
name: socket-dir

0 comments on commit 196f8b0

Please sign in to comment.