[Infrastructure as Code (IaC)] Use Pulumi kubernetes (K8S) Helm Chart to deploy nfs-client-provisioner
nfs-client-provisioner
nfs-client-provisioner chart will deploy the Kubernetes nfs provisioner. This provisioner is intended for connecting to a pre-existing NFS server, and not includes a built in NFS server. If you want a built in NFS Server, please consider using the nfs-client-provisioner - https://github.com/helm/charts/tree/master/stable/nfs-client-provisioner instead.
Pulumi - Modern Infrastructure as Code - https://www.pulumi.com/ is a Modern Infrastructure as Code (IaC) to create, deploy, and manage infrastructure on any cloud using familiar programming languages and tools.
This article is about how to use Pulumi, kubernetes (K8S) provider, Helm Chart and TypeScript SDK to deploy nfs-client-provisioner within Kubernetes (K8S).
The NFS client provisioner - https://github.com/kubernetes-incubator/external-storage/tree/master/nfs-client is an automatic provisioner for Kubernetes that uses your already configured NFS server, automatically creating Persistent Volumes.
Pulumi’s Cloud Native SDK makes it easy to target any Kubernetes environment to provision a cluster, configure and deploy applications, and update them as required.
Helm Chart is a component representing a collection of resources described by an arbitrary Helm Chart.
The Chart can be fetched from any source that is accessible to the helm command line. Values in the values.yml file can be overridden using ChartOpts.values (equivalent to --set or having multiple values.yml files). Objects can be transformed arbitrarily by supplying callbacks to ChartOpts.transformations
.
As of Nov 13, 2020, charts in this repo will no longer be updated. For more information, see the Helm Charts Deprecation and Archive Notice, and Update.
You can use Azure Helm mirror - http://mirror.azure.cn/kubernetes/charts/ to replace https://kubernetes-charts.storage.googleapis.com
Prerequisites
-
Kubernetes (K8s) is an open-source system for automating deployment, scaling, and management of containerized applications.
See Getting started | Kubernetes - https://kubernetes.io/docs/setup/ to leanr more.
-
Pulumi - Modern Infrastructure as Code - https://www.pulumi.com/
Pulumi is a modern infrastructure-as-code platform that allows you to use common programming languages, tools, and frameworks, to provision, update, and manage cloud infrastructure resources.
Install the Pulumi - https://www.pulumi.com/ CLI.
1
2Mac OS X
brew install pulumiSee Download and Install | Pulumi - https://www.pulumi.com/docs/get-started/install/ to learn more about others OS.
-
Node.js - https://nodejs.org/en/
Node.js® is a JavaScript runtime built on Chrome’s V8 JavaScript engine.
Install Node.js - https://nodejs.org/en/ CLI.
1
2Mac OS X
brew install nodeSee Node.js - https://nodejs.org/en/ to learn more about others OS.
-
Pre-existing NFS server
You must have a pre-existing NFS server installed according to NFS Server and Client Installation on CentOS 7 - https://www.howtoforge.com/nfs-server-and-client-on-centos-7, or use which is provided by the third-party vendors(such as [5] File Storage NAS: Reliable Network Attached Storage - Alibaba Cloud - https://www.alibabacloud.com/product/nas).
Usage
Pulumi New
Create the workspace directory.
1 | mkdir -p col-example-pulumi-typescript-nfs-client-provisioner |
Pulumi login into local file system.
1 | pulumi login file://. |
Pulumi new a project with kubernetes-typescript SDK.
1 | pulumi new kubernetes-typescript |
The above command will create some files within the current directory.
1 | tree . -L 1 |
Install js-yaml
package to load and parse yaml file.
1 | npm i js-yaml |
Pulumi Configuration
Configure Kubernetes
By default, Pulumi will look for a kubeconfig file in the following locations, just like kubectl:
-
The environment variable:
$KUBECONFIG
, -
Or in current user’s default kubeconfig directory:
~/.kube/config
If the kubeconfig file is not in either of these locations, Pulumi will not find it, and it will fail to authenticate against the cluster. Set one of these locations to a valid kubeconfig file, if you have not done so already.
Configure Values.yaml
Edit values.yaml and replace content within {{ }}
.
1 | # values.yaml |
See and modify main.ts file.
1 | // main.ts |
Pulumi Up
Run pulumi up to create the namespace and pods.
1 | pulumi up |
See pods about nfs-client-provisioner.
1 | kubectl get pods -n nfs-client-provisioner |
check the StorageClass status.
1 | kubectl get sc |
Pulumi Destroy
Destroy all resources created by Pulumi.
1 | pulumi destroy |
FAQs
bad option; for several filesystems (e.g. nfs, cifs) you might need a /sbin/mount. helper program
1 | MountVolume.SetUp failed for volume "pvc-c10001c32-f2dd-4f8c-8d19-bd8c2e01b5cf" : mount failed: exit status 32 Mounting command: mount Mounting arguments: -t nfs -o nolock,tcp,noresvport,vers=4.1 bad option; for several filesystems (e.g. nfs, cifs) you might need a /sbin/mount.<type> helper program. |
Install nfs packages to solve that issue.
1 | Debian, Ubuntu |
Unable to attach or mount volumes: unmounted volumes=[config storage xxxxxx-volume], unattached volumes=[config storage xxxxxx-volume]: timed out waiting for the condition
Modify mountOptions
to vers=4.1
and nolock,tcp,noresvport
to fix that issue.
1 | # values.yaml |
References
[2] [charts/stable/nfs-client-provisioner at master · helm/charts · GitHub - https://github.com/helm/charts/tree/master/stable/nfs-client-provisioner]
[3] Azure Helm mirror - http://mirror.azure.cn/kubernetes/charts/
[4] Kubernetes Getting Started | Pulumi - https://www.pulumi.com/docs/get-started/kubernetes/
[5] Pulumi - Modern Infrastructure as Code - https://www.pulumi.com/
[6] Kubernetes - https://kubernetes.io/
[7] TypeScript: Typed JavaScript at Any Scale. - https://www.typescriptlang.org/