Deploy Client Applications in Openshift
After successful server side deployment, you need to deploy the client application with NCache within the Kubernetes cluster.
Connect Client to NCache
In order to connect the client application to your cache cluster use either of the two methods:
You can connect to cache by adding the name of the Cache Discovery Service (headless service) which was created beforehand in the client.ncconf of your client.
Under the cache configuration for demoClusteredCache, add the name of the service cacheserver in the
<server name> tag.
<cache id="democlusteredcache" ..."> <server name="cacheserver"/>
Use NCache Client Dockerfile
Use your NCache client dockerfile containing the commands to create a container image by using runtime .NET or runtime SDK. This allows using both InProc and OutProc caches.
In order to create the dockerfile:
- Get the dockerfile from GitHub, provided by NCache.
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.
In the Resources folder placed with the other files downloaded from NCache docker repository, place your client application.
Go to startup.sh in the Resources folder.
sleep infinitywith the your client application's path and save the startup.sh file.
In order to follow the alternative method, follow the steps below:
- Add the path to your application in the COPY command in the dockerfile.
- In the startup.sh file, replace the
sleep infinitytag with your application's path and save the file.
# Setting base image for dotnet FROM mcr.microsoft.com/dotnet/core/sdk:3.0
Add the client application path in the
ENTRYPOINT section of the dockerfile to not use startup.sh altogether.
Once the client dockerfile is edited, execute the following commands to convert your client application's dockerfile to a container image and upload it.
Make sure that docker is installed on your machine to create the client docker image.
docker build . -t [image tag] docker push [repository]:[image tag]
In your dockerfile, it is recommended to use the .NET SDK for the added benefit of coming packed with the PowerShell tool.
Execute the following command on you command line tool to access PowerShell tool inside your Kubernetes cluster.
oc exec client-pod-name -- pwsh -NoExit
After successful execution, import NCache PowerShell Module using the following command:
You can now execute PowerShell commands on any pods inside the Kubernetes cluster. In order to get a complete list of NCache PowerShell tools please refer to NCache PowerShell Reference.
Embed NCache Client Libraries
For applications with no NCache installation, you can use Nuget packages to deploy NCache client in your Kubernetes cluster.
For your client application deployment in OpenShift, create a YAML file. Here is a sample client.yaml file:
apiVersion: apps/v1beta1 kind: Deployment metadata: name: client labels: app: client spec: replicas: 1 template: metadata: labels: app: client spec: imagePullSecrets: - name: ncache-private containers: - name: client image: your-client-application-repo-path ports: - name: management-tcp containerPort: 8250 - name: management-http containerPort: 8251 - name: client-port containerPort: 9800
Import the YAML file using either OpenShift web portal or command line tool. In order to check the client container status use the following command:
oc get pods -o wide
The next chapter explains monitoring of the cache cluster and clients after deploying the client applications.