Create NCache Client Deployment
To run NCache client in your Azure Kubernetes cluster, you need to deploy your client application in the cluster. There are multiple ways to create NCache client deployment and these vary depending upon your requirements.
Use NCache Client Dockerfile
You can create your NCache client dockerfile that contains the commands to create a container image using either runtime .NET or .NET SDK. This allows you to use both InProc and OutProc caches.
Follow the steps mentioned below to start creating your client dockerfile.
Access the dockerfile provided by Alachisoft from:
- Place NCache installation setup in the Resources folder.
In case of .NET SDK, you need to change the base image tag as shown below and this will allow access to runtime and other packages like PowerShell tool.
- Add your client application in the Resources folder.
- Go to startup.sh in the Resources folder.
- Add the name of your client application in place of
- Save the startup.sh file.
- In the dockerfile, add the path to your client application under the COPY command and save the file.
COPY [application path]
- Go to the startup.sh file and replace the
sleep infinitytag with the path of your application and save the file.
# Setting base image for dotnet FROM mcr.microsoft.com/dotnet/core/sdk:3.0
You can simply add your client application path in the
ENTRYPOINT section of the dockerfile and spare the need of using startup.sh altogether.
After you have finished editing the client dockerfile, go to your build environment and execute the following commands. These commands convert your client application's dockerfile into a container image and upload it to the container registry.
docker build . -t [image tag] docker push [repository]:[image tag]
You need to have docker installed on your machine to create your client docker image and run this command from inside the directory containing your dockerfile.
The plus point about using .NET SDK is that it comes packed with not only runtime but also PowerShell tool. Hence, in order to automate scripting, it is recommended to use .NET SDK environment.
Execute the following command on a shell platform to get access to PowerShell tool inside your Kubernetes cluster.
kubectl exec pod-name -- pwsh -NoExit
You can verify that you have entered PowerShell by the tag
Now, you need to import NCache PowerShell module to start using NCache specific PowerShell tools.
To use NCache PowerShell module, NCache must be installed on your machine.
This will allow you to execute PowerShell commands on any of the pods present inside the Kubernetes cluster. From here on, you can start, stop, add, remove nodes all while staying inside the Kubernetes cluster.
Embed NCache Client Libraries in Application
In case you do not have NCache installed on the machine that is running your client application, then you can use NuGet packages to deploy NCache client in your Kubernetes cluster. This only allows access to InProc caches.
Install NuGet packages provided by Alachisoft in your client application to use NCache without running NCache as client.
You will find the required NuGet packages at NCache NuGet Packages
To install these packages in your client application, follow the steps mentioned in Install NuGet in Microsoft Visual Studio
Once the packages have been successfully installed, create an image of your client application.
- Here, you need to create another YAML file for deploying client in your Kubernetes cluster. Let's call this file client.yaml.
The parameters required to create this YAML file ready to be deployed are mentioned in the Properties table.
kind: Deployment apiVersion: apps/v1beta1 # Underlying Kubernetes version metadata: name: client spec: replicas: 1 template: metadata: labels: app: client spec: imagePullSecrets: - name: client-private nodeSelector: "beta.kubernetes.io/os": linux containers: - name: client image: # Your docker client image here ports: - name: port1 containerPort: 8250 - name: port2 containerPort: 8251 - name: port3 containerPort: 9800
To deploy this file as a pod in the Kubernetes cluster, execute the following command in the Azure Cloud Shell:
kubectl create -f [dir]/client.yaml
The next step is to create NCache cache cluster, explained in the next chapter.