• Stars
    star
    211
  • Rank 186,400 (Top 4 %)
  • Language
    Shell
  • License
    MIT License
  • Created over 6 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

CIFS Flexvolume Plugin for Kubernetes

CIFS Flexvolume Plugin for Kubernetes

Driver for CIFS (SMB, Samba, Windows Share) network filesystems as Kubernetes volumes.

Background

Docker containers running in Kubernetes have an ephemeral file system: Once a container is terminated, all files are gone. In order to store persistent data in Kubernetes, you need to mount a Persistent Volume into your container. Kubernetes has built-in support for network filesystems found in the most common cloud providers, like Amazon's EBS, Microsoft's Azure disk, etc. However, some cloud hosting services, like the Hetzner cloud, provide network storage using the CIFS (SMB, Samba, Windows Share) protocol, which is not natively supported in Kubernetes.

Fortunately, Kubernetes provides Flexvolume, which is a plugin mechanism enabling users to write their own drivers. There are a few flexvolume drivers for CIFS out there, but for different reasons none of them seemed to work for me. So I wrote my own, which can be found on github.com/fstab/cifs.

Installing

The flexvolume plugin is a single shell script named cifs. This shell script must be available on the Kubernetes master and on each of the Kubernetes nodes. By default, Kubernetes searches for third party volume plugins in /usr/libexec/kubernetes/kubelet-plugins/volume/exec/. The plugin directory can be configured with the kubelet's --volume-plugin-dir parameter, run ps aux | grep kubelet to learn the location of the plugin directory on your system (see #1). The cifs script must be located in a subdirectory named fstab~cifs/. The directory name fstab~cifs/ will be mapped to the Flexvolume driver name fstab/cifs.

On the Kubernetes master and on each Kubernetes node run the following commands:

VOLUME_PLUGIN_DIR="/usr/libexec/kubernetes/kubelet-plugins/volume/exec"
mkdir -p "$VOLUME_PLUGIN_DIR/fstab~cifs"
cd "$VOLUME_PLUGIN_DIR/fstab~cifs"
curl -L -O https://raw.githubusercontent.com/fstab/cifs/master/cifs
chmod 755 cifs

The cifs script requires a few executables to be available on each host system:

  • mount.cifs, on Ubuntu this is in the cifs-utils package.
  • jq, on Ubuntu this is in the jq package.
  • mountpoint, on Ubuntu this is in the util-linux package.
  • base64, on Ubuntu this is in the coreutils package.

To check if the installation was successful, run the following command:

VOLUME_PLUGIN_DIR="/usr/libexec/kubernetes/kubelet-plugins/volume/exec"
$VOLUME_PLUGIN_DIR/fstab~cifs/cifs init

It should output a JSON string containing "status": "Success". This command is also run by Kubernetes itself when the cifs plugin is detected on the file system.

Running

The plugin takes the CIFS username and password from a Kubernetes Secret. To create the secret, you first have to convert your username and password to base64 encoding:

echo -n username | base64
echo -n password | base64

Then, create a file secret.yml and use the ouput of the above commands as username and password:

apiVersion: v1
kind: Secret
metadata:
  name: cifs-secret
  namespace: default
type: fstab/cifs
data:
  username: 'ZXhhbXBsZQ=='
  password: 'bXktc2VjcmV0LXBhc3N3b3Jk'

Apply the secret:

kubectl apply -f secret.yml

You can check if the secret was installed successfully using kubectl describe secret cifs-secret.

Next, create a file pod.yml with a test pod (replace //server/share with the network path of your CIFS share):

apiVersion: v1
kind: Pod
metadata:
  name: busybox
  namespace: default
spec:
  containers:
  - name: busybox
    image: busybox
    command:
      - sleep
      - "3600"
    imagePullPolicy: IfNotPresent
    volumeMounts:
    - name: test
      mountPath: /data
  volumes:
  - name: test
    flexVolume:
      driver: "fstab/cifs"
      fsType: "cifs"
      secretRef:
        name: "cifs-secret"
      options:
        networkPath: "//server/share"
        mountOptions: "dir_mode=0755,file_mode=0644,noperm"

Start the pod:

kubectl apply -f pod.yml

You can verify that the volume was mounted successfully using kubectl describe pod busybox.

Testing

If everything is fine, start a shell inside the container to see if it worked:

kubectl exec -ti busybox /bin/sh

Inside the container, you should see the CIFS share mounted to /data.

More Repositories

1

grok_exporter

Export Prometheus metrics from arbitrary unstructured log data.
Go
889
star
2

h2c

http2client
Go
272
star
3

promagent

Prometheus Monitoring for Java Web Applications without Modifying their Source Code
Java
83
star
4

prometheus-for-java-developers

Prometheus for Java Developers Demo
79
star
5

go-programming-for-java-developers

Golang Programming Workshop
72
star
6

http2-examples

Java
49
star
7

docker-aws-cli

Docker image for running the AWS command line interface.
28
star
8

diy-kubernetes

Do-It-Yourself Kubernetes in the Hetzner Cloud
HCL
14
star
9

fosdem-2023

Shell
12
star
10

docker-mutt

11
star
11

docker-weechat-otr

Run the weechat IRC client with Off-the-Record (OTR) encryption.
11
star
12

javazone-2023

Java
8
star
13

basic-ubuntu-server-setup

3
star
14

promagent-operator

Demo: Kubernetes operator for the Prometheus monitoring Java agent
Go
3
star
15

jug-oberpfalz-prometheus-java

3
star
16

exim_prometheus_exporter

Go
3
star
17

docker-grip

Docker image for viewing Markdown pages
3
star
18

quarkus-demo

Java
3
star
19

jcon-2023

Java
3
star
20

java-demo

Java Demo Application for Kubernetes
Java
2
star
21

jbcn.conf-2022

Java
2
star
22

docker-grok_exporter-compiler

Shell
2
star
23

docker-bower

develop bower projects without installing bower
Shell
2
star
24

diy-kubernetes-basic

Basic Kubernetes Setup with Terraform and Ansible
HCL
2
star
25

client_java-otel-example

Example of Pushing Prometheus Metrics to a Prometheus Server via OpenTelemetry's OTLP
Java
1
star
26

docker-prometheus-demo

Ubuntu with Prometheus downloads in /root/.
1
star
27

pam-truecrypt

C
1
star
28

docker-wildfly-http2

Shell
1
star
29

docker-ubuntu

Extended Ubuntu base image
1
star
30

devoxx-be-2022-latency

Java
1
star
31

s3diff

Compare a local directory with its back-up on Amazon S3.
Ruby
1
star
32

docker-asciidoc

1
star
33

spring-boot-2-opentelemetry-traces

Demo project showing Prometheus Exemplars for Spring Boot 2 Prometheus metrics with OpenTelemetry traces
Java
1
star
34

music-box

C
1
star
35

micrometer-config-example

Examples of How To Configure Micrometer Metrics in Spring Boot
Java
1
star
36

docker-go

Test go programs in a Linux container.
1
star
37

node-imap

An IMAP client module for node.js.
JavaScript
1
star