How to Mount CIFS Windows Share to Kubernetes Pod with Flexvolume

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.

Related Posts

Everything You Ever Wanted to Know About Istio but Were Afraid to Ask

Istio is a powerful service mesh that integrates natively with Kubernetes, I have been using Istio as my service mesh, ingress, and egress gateways on my personal…

How to Monitor Your Enphase Home Solar System with Telegraf

How to collect metrics from an Enphase Envoy PV system, with telegraf and influxdb.

How to Deploy Anthos on Bare Metal On-Prem

Introduction The main advantage of Anthos on BM over Anthos on VMWare for on-prem deployments is the ability to run Anthos clusters without a hypervisor license. Cluster…

OPA Gatekeeper: Bringing Law and Order to Kubernetes

Introduction Open Policy Agent (OPA) is a policy based control agent that is able to be integrated on various platforms. For the sake of this document we…

How to Setup Anthos on GKE Autopilot with Private Certificate Authority

What You Will Create The guide will set up the following: 2 Private GKE autopilot clusters with master global access ASM with multicluster mesh IstioIngress gateway to…

How to Setup a pfSense IPsec VPN Connection Behind a Router to Google Cloud

A tutorial on how to setup a virtual pfSense router behind a main router for VPN communications with Google Cloud Platform.

Leave a Reply Cancel reply

Exit mobile version