Create NCache Operator in Kubernetes
An Operator is a custom controller running inside a pod which watches over the cluster you created. To run an operator inside your Kubernetes cluster, you need to create and deploy a manifest file containing the desired metadata. Follow the steps mentioned in this chapter to understand how to create a file that contains NCache related operator specifications and deploy this file in your cluster.
Create Operator Manifest File
The manifest file for the operator, ncache_operator.yaml, contains operator pod's specification that includes the following information:
- Storage
- Persistent Volume
- Container image of the Operator to be deployed
The layout of your ncache_operator.yaml should be:
Note
The parameters required to create this YAML file, ready to be deployed, are explained in the Properties section.
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: storage
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer
---
kind: PersistentVolume
apiVersion: v1
metadata:
name: persistvolume
spec:
capacity:
storage: 25M # change as per your requirement
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: storage
nfs:
path: /path/volume # replace this with the path to the volume to mount
server: 10.10.10.10
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values: # change according to your node names
- node1
- node2
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: persistvolume-claim
spec:
accessModes:
- ReadWriteOnce
storageClassName: storage
resources:
requests:
storage: 25M # change as per your requirement
---
kind: Deployment
apiVersion: apps/v1
metadata:
name: ncache-operator
spec:
replicas: 1
selector:
matchLabels:
name: ncache-operator
template:
metadata:
labels:
name: ncache-operator
spec:
serviceAccountName: ncache-operator
tolerations:
- key: "node-role.kubernetes.io/master"
effect: "NoSchedule"
operator: "Exists"
nodeSelector:
"kubernetes.io/os": linux
initContainers:
- name: check-for-read-write-permissions
image: mcr.microsoft.com/powershell:latest
command: ['/bin/bash', '-c', 'if [ $(stat -L -c "%a" $OP_MOUNT_PATH) == 777 ]; then exit 0; else exit 1; fi;']
volumeMounts:
- name: my-persistent-storage
mountPath: /alachisoft/ncache-operator
env:
- name: OP_MOUNT_PATH
value: "/alachisoft/ncache-operator"
containers:
- name: ncache-operator
# Replace this with the built image name
image: ncache-operator:latest
imagePullPolicy: IfNotPresent
env:
- name: WATCH_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: OPERATOR_NAME
value: "ncache-operator"
- name: OP_MOUNT_PATH
value: "/alachisoft/ncache-operator"
volumeMounts:
- name: my-persistent-storage
mountPath: /alachisoft/ncache-operator
volumes:
- name: my-persistent-storage
persistentVolumeClaim:
claimName: persistvolume-claim
Important
- You need to make sure that requested storage is available on the same node on which you are deploying the operator.
- It is recommended to not use local storage if you have multiple replicas of the operator inside the cluster.
Deploy NCache Operator in Kubernetes
To deploy the created Operator deployment file in Kubernetes, run the following command in cloud shell:
kubectl create -f [dir]/ncache_operator.yaml
This will create an Operator as a pod inside your cluster with the name specified in the YAML file. To verify, you can execute the following command:
kubectl get deployments
Properties
The properties required to create role binding in Kubernetes are explained below:
Parameter | Description |
---|---|
-kind |
This can be many different types like a Deployment, a StorageClass, PersistentVolume or PersistentVolumeClaim. |
-apiVersion |
Specifies the version of the kind and it depends on the underlying version of Kubernetes. |
-name |
Specifies the name of the deployment. |
-provisioner |
Specifies which provisioner should be used to define the storage class objects. |
-volumeBindingMode |
Specifies when volume binding and dynamic provisioning should occur. |
-capacity |
Specifies the overall capacity of the volume to be mounted. |
-accessModes |
Specifies the access mode of the persistent volume to be mounted. |
-persistentVolumeReclaimPolicy |
Specifies what to do with the volume after it has been released of its claim. |
-storageClassName |
Specifies the name of the storage class. If not provided, the cluster will use default storage class inside the cluster. |
-storageClassName |
Specifies the name of the storage class. If not provided, the cluster will use default storage class inside the cluster. |
-nodeAffinity |
Specifies constraints that limit which nodes this volume can be accessed from. |
-replicas |
Specifies the number of replica pods to be created at the time of deployment. |
-selector |
Specifies labels to filter the set of volumes. |
-template |
Specifies the template of the deployment pod. |
-template.spec.serviceAccountName |
Specifies the name of the service account that you specified when creating service_account.yaml. |
-template.spec.tolerations |
Specifies the pod to schedule onto nodes with matching taints. |
-template.spec.nodeSelector |
Specifies the node on which the underlying container needs to be hosted. |
-template.spec.initContainers |
Specifies the details of specialized containers that run before the actual container to verify whether NCache has read/write access to the persistent storage. |
-template.spec.containers |
Specifies the details of the actual container on which NCache operator needs to be run. |
-template.spec.volumes |
Specifies the persistent volume set earlier with the container that runs the operator. |
This operator deployment does not include the spec
required to deploy desired resources in the cluster. To do that, you need to define custom resources in your cluster, the steps of which have been explained in the next chapter.
See Also
Create Service Account
Create Role Definition
Create NCache Operator
Create Custom Resources