Background
When setting up my bare-metal Kubernetes cluster I initially used a NFS provisioner with a Windows NFS share for my PV, however Windows NFS shares often cause more issues than they solve. Given this I decided to use CIFS as a work around.
Setup
In order to use CIFS mounts on Kubernetes there are a few things you need to do on each node, including the master.
First install the required packages on each node
sudo apt install cifs-utils jq
On all nodes run the following command
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
Check if the installation was successful with the following command on each node
VOLUME_PLUGIN_DIR="/usr/libexec/kubernetes/kubelet-plugins/volume/exec"
$VOLUME_PLUGIN_DIR/fstab~cifs/cifs init
Kubectl Commands
Create base64 encoded credentials for share
echo -n username | base64
echo -n password | base64
Create a secret.yml file and replace username and password with the aboved hashed output
apiVersion: v1
kind: Secret
metadata:
name: cifs-secret
namespace: default
type: fstab/cifs
data:
username: 'ZXhhbXBsZQ=='
password: 'bXktc2VjcmV0LXBhc3N3b3Jk'
Apply Kubernetes secret
kubectl apply -f secret.yml
Kubernetes Deployment
I have included a sample deployment of Organizr, more information about Organizr can be found here https://github.com/causefx/Organizr.
apiVersion: apps/v1 | |
kind: Deployment | |
metadata: | |
annotations: | |
name: organizr | |
namespace: default | |
spec: | |
progressDeadlineSeconds: 600 | |
replicas: 1 | |
revisionHistoryLimit: 10 | |
selector: | |
matchLabels: | |
app: organizr | |
strategy: | |
rollingUpdate: | |
maxSurge: 0 | |
maxUnavailable: 100% | |
type: RollingUpdate | |
template: | |
metadata: | |
creationTimestamp: null | |
labels: | |
app: organizr | |
io.portainer.kubernetes.application.name: organizr | |
spec: | |
containers: | |
- env: | |
- name: PGID | |
value: "1000" | |
- name: PUID | |
value: "1000" | |
image: organizr/organizr | |
imagePullPolicy: Always | |
name: organizr | |
resources: {} | |
terminationMessagePath: /dev/termination-log | |
terminationMessagePolicy: File | |
volumeMounts: | |
- mountPath: /config | |
name: config | |
dnsPolicy: ClusterFirst | |
restartPolicy: Always | |
schedulerName: default-scheduler | |
securityContext: {} | |
terminationGracePeriodSeconds: 30 | |
volumes: | |
- flexVolume: | |
driver: fstab/cifs | |
fsType: cifs | |
options: | |
mountOptions: dir_mode=0777,file_mode=0777,iocharset=utf8,noperm,nounix,rw | |
networkPath: <CIFS_SHARE_PATH> | |
secretRef: | |
name: cifs-secret | |
name: config |