Skip to content

Getting Started with In-Memory Key-Value Cache

This guide will walk you through the process of getting a managed Valkey instance and connecting to it from your application within the Kubernetes cluster.

Step 1: Request a Valkey Instance

The In-Memory Key-Value Cache is a managed service. To get started, you need to request an instance to be provisioned for you.

When you contact us, please specify which deployment mode you require. We support the following modes:

  • Standalone: Deploys a single Valkey instance. This is suitable for development, testing, or caching scenarios where high availability is not a primary concern.
  • Primary-Replica with Sentinel: Deploys a highly available cluster with one primary for write operations and one or more replicas for read operations. Valkey Sentinel monitors the instances and automatically handles failover, promoting a replica to primary if the original primary becomes unavailable.

Once the instance is ready, we will provide you with its unique identifier, which we will refer to as <$valkey_name>.

Step 2: Configure Application Access

To connect to your Valkey instance, your application needs the correct network configuration and credentials.

Network Policy

Your Valkey instance is isolated by a network policy. To allow your application pods to connect to it, you must add a specific label to them.

In your Deployment or Pod manifest, add the following label:

spec:
  # ... other pod specs
  template:
    metadata:
      labels:
        netic.dk/valkey-egress: "<$valkey_name>"
    # ... other pod specs

Replace <$valkey_name> with the unique identifier provided to you.

Connection Credentials

We automatically sync the required credentials and connection details into your namespace using two Kubernetes Secrets.

  1. valkey-<$valkey_name>-ca: This secret contains the ca.crt data key, which holds the Certificate Authority (CA) certificate for your Valkey instance.
  2. valkey-<$valkey_name>-connection-info: This secret contains the following data keys for connecting to the instance:
    • host: The hostname for the Valkey service.
    • username: The username for authentication.
    • password: The password for authentication.
    • connection_string: A ready-to-use connection string that includes the username, password, and host.

The recommended way to use these secrets is to mount their keys as environment variables in your application's container.

Manifest Example

In your Deployment manifest, you would add the following to your application container's definition:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-application
spec:
  # ... other deployment specs
  template:
    metadata:
      labels:
        # Replace <$valkey_name> with your instance identifier
        netic.dk/valkey-egress: "<$valkey_name>"
    spec:
      containers:
      - name: my-app-container
        image: your-image/my-app
        env:
        - name: VALKEY_HOST
          valueFrom:
            secretKeyRef:
              # Replace <$valkey_name> with your instance identifier
              name: valkey-<$valkey_name>-connection-info
              key: host
        - name: VALKEY_USERNAME
          valueFrom:
            secretKeyRef:
              name: valkey-<$valkey_name>-connection-info
              key: username
        - name: VALKEY_PASSWORD
          valueFrom:
            secretKeyRef:
              name: valkey-<$valkey_name>-connection-info
              key: password

Your application can then read the host, username, and password from these environment variables to establish a connection using any standard Valkey client library.

Next Steps

You are now ready to use your Valkey cache.

  • You can use any Valkey-compatible client library for your programming language to interact with the cache.
  • For a complete list of commands and information on the available data structures, please refer to the official Valkey documentation.