Deploy NCache Open Source with Kubernetes
NCache Open Source can be deployed on Kubernetes using YAML manifests to create the server pods and networking services. A StatefulSet maintains the server deployment, while Kubernetes Services provide access to the NCache servers.
This page describes how to deploy two NCache servers, configure a clustered cache, and apply configuration changes. Cache configuration is managed through the NCache configuration file, with an NCache service restart required for changes to take effect.
Prerequisites
Before you begin, make sure that:
- You have a running Kubernetes cluster with Linux worker nodes and sufficient resources for two NCache servers.
kubectlis installed and configured to access the intended cluster.- You have permission to create StatefulSets and Services in the deployment namespace.
- You have access to the NCache Open Source container image and any credentials required by its registry.
- The application network can reach the NCache client endpoint and the ports required by your cache configuration.
Deployment Process
Step 1: Prepare the Deployment Files
The deployment uses the following YAML files:
- ncache.yaml defines the StatefulSet and NCache server containers. The supplied configuration creates two server pods.
- discoveryservice.yaml defines the headless Service used to identify the server pods.
- client-gatewayservice.yaml exposes the NCache client port through a NodePort Service.
In ncache.yaml, specify the NCache Open Source image you intend to deploy. If the registry requires authentication, create an image pull Secret in the deployment namespace and reference it through imagePullSecrets. Remove the imagePullSecrets entry if authentication is not required.
Ensure that the StatefulSet's serviceName matches the headless Service name. With the supplied discoveryservice.yaml, use the following value in ncache.yaml:
spec:
serviceName: cacheserver
Retain the remaining StatefulSet settings, including its selectors, pod labels, and container ports.
The supplied client-gatewayservice.yaml uses type: NodePort. Ensure that the assigned node port is reachable from the application network.
Step 2: Deploy the NCache Servers
Create a namespace for the deployment:
kubectl create namespace ncache
If the namespace already exists, continue with the deployment commands.
Apply the headless Service, StatefulSet, and client gateway:
kubectl apply --namespace ncache -f discoveryservice.yaml
kubectl apply --namespace ncache -f ncache.yaml
kubectl apply --namespace ncache -f client-gatewayservice.yaml
Check the server pods and their assigned IP addresses:
kubectl get pods --namespace ncache -l app=ncache -o wide
The default deployment creates ncache-0 and ncache-1. If a container fails to start, inspect its events and logs before configuring the cache:
kubectl describe pod ncache-0 --namespace ncache
kubectl logs ncache-0 --namespace ncache
Repeat these checks for the affected pod.
Step 3: Configure the Cache
Prepare the NCache configuration file with the cache name, topology, size, communication ports, and server addresses required by your deployment.
Use the server pod IP addresses reported in Step 2 when defining the cache members. Ensure that both servers use consistent cache settings and identify the same members.
Apply the configuration file to each NCache server. Keep a copy of the configuration outside the containers so that it remains available when a pod is replaced.
Creating the StatefulSet and Services deploys the server containers; it does not replace the cache configuration required to form the NCache cluster.
Step 4: Apply the Configuration Changes
After updating the configuration on each server, restart the NCache service on that server so that it loads the changes.
For an existing cache, plan the restart according to its topology and the application's availability requirements. Verify the first server before proceeding with the next, and preserve any required data before an operation that could remove it.
After the restart, inspect the server logs and confirm that the intended cache configuration has been loaded.
Step 5: Connect and Verify the Application
Inspect the client gateway Service:
kubectl get service gateway --namespace ncache
For applications outside Kubernetes, use a reachable worker-node address and the NodePort assigned to client port 9800. Ensure that the application can reach any additional server endpoints required by the cache.
Configure the application to connect to the cache by name using the NCache client library. Verify the deployment by adding an item to the cache and retrieving it from the application.
If the connection fails, check the cache name, server configuration, client endpoint, and network access. Inspect the server logs for configuration or connection errors.
Update the Deployment
To change Kubernetes settings, edit the relevant YAML manifest and apply it again with kubectl apply.
To change NCache cache settings, update the NCache configuration file on the affected servers and restart their NCache services. Applying a Kubernetes manifest alone does not apply changes to an NCache configuration file maintained separately.
Pod replacement can change server IP addresses. After a replacement, verify that the configured cache members match the running servers and update the configuration where necessary.
Remove the Deployment
Remove the resources using the same manifests and namespace:
kubectl delete --namespace ncache -f client-gatewayservice.yaml
kubectl delete --namespace ncache -f ncache.yaml
kubectl delete --namespace ncache -f discoveryservice.yaml
Deleting the StatefulSet removes its server pods and makes the caches unavailable. Preserve any required data and configuration before removing the deployment.
See Also
Kubernetes Self-Deployment
Deploy TLS With NCache Kubernetes