Create NCache Client in EKS
After deploying the NCache headless cache discovery service, you can now deploy your NCache client application(s) in the cluster. There are multiple ways to create NCache client deployment and these vary depending upon your requirements.
Embed NCache Client Libraries in Application
Note
If you want to use OutProc client caches and monitor your client-side NCache performance counters, please refer to the next section instead.
To allow for the NCache clients to communicate with the servers, you can simply add the NCache client libraries to your application project solution. Using these, you can then use the NCache Client API to generate code for cache management and CRUD operations.
The NCache libraries also allow you to use InProc client caches but do not offer OutProc client caches to be shared between multiple applications running in same container nor can you monitor client-side performance counters.
For .NET applications, you can use NuGet packages to deploy NCache client in your cluster if you don't have NCache installed on the machine that is running your client application.
You will find the NuGet packages provided by Alachisoft at NCache NuGet Packages
To install these packages in your client application, follow the steps provided in Install NuGet in Microsoft Visual Studio
Use NCache Client Dockerfile
To create an image of your client application, you can create a 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 client caches.
Create Client Dockerfile
To create your client Dockerfile, follow the steps mentioned below:
Access the Dockerfile provided by Alachisoft from:
https://github.com/Alachisoft/NCache-Docker/tree/master/enterprise/client/- Place NCache installation setup tag.gz file in the resources folder.
Note
In case of .NET SDK, you need to change the base image tag in the Dockerfile to the one shown below and this will allow access to runtime and other packages like PowerShell tool to enable automating scripts from within the client containers.
FROM mcr.microsoft.com/dotnet/core/sdk
Method 1
- Place your client application in the resources folder.
- Go to startup.sh in the resources folder and replace
sleep infinity
with the name of your client application. - Save the startup.sh file.
Method 2
- In the Dockerfile, add the path to your client application under the COPY command and save the file like shown below:
COPY [application path] . # assuming you are in the /app directory
- Go to the startup.sh file and replace the
sleep infinity
tag with the path of your application and save the file.
Tip
You can simply add your client application path in the ENTRYPOINT
section of the Dockerfile and avoid using startup.sh altogether.
Create Docker Client Image
Once the Dockerfile is updated according to your requirements, execute the following commands from your build environment. These commands convert your client application's Dockerfile into a container image and upload it on the container registry.
docker build . -t [image tag]
docker push [repository]:[image tag]
Note
- You need to have Docker installed on your machine to create your client Docker image.
- You need to run these commands from inside the directory that contains your Dockerfile.
Import NCache PowerShell Tool
The advantage of creating your client image with .NET SDK is that it comes packed with not only .NET Runtime but also PowerShell tool. Hence, it is recommended to use .NET SDK environment in order to automate scripting in PowerShell.
Execute the following command on a shell platform to get access to PowerShell tool inside your client pod.
kubectl exec <client_pod_name> -- pwsh -NoExit
You can verify that you have entered PowerShell by the tag PS:>
.
Now, you need to import NCache PowerShell module to start using NCache specific PowerShell tools. Execute the following command in your PowerShell environment to import NCache PowerShell tools.
Note
To use NCache PowerShell module, NCache must be installed on your machine.
Import-Module /opt/ncache/bin/tools/ncacheps
This will allow you to execute PowerShell commands on any of the pods present inside the Elastic Kubernetes cluster. From here on, you can start, stop, add, remove NCache nodes all while staying inside your cluster.
After creating and pushing the application container images to a Docker repository e.g. DockerHub, ECR, you can then create and deploy the Kubernetes resources needed to run the NCache client applications on the Kubernetes cluster.
The next step is to create NCache client deployment, explained in the next chapter.
See Also
Create Access for NCache Management in EKS
Create NCache Client Deployment in EKS
Create Cache Cluster in EKS
Monitor NCache Cluster and Clients in EKS