Azure Managed Redis
Gappynator can provision an Azure Managed Redis cache for your team and give your applications access to it. You describe the cache with a Redis resource, list the applications that may use it, and reference it from your Application. Gappynator creates the cache, the private connectivity, the data access for your application's workload identity and the network policy.
What you get
- A managed cache with a
defaultdatabase, created in your team's Azure subscription and owned by your team. - Private access only. The cache is not reachable from the internet, only from your applications in GAP.
- Entra ID authentication only. There are no access keys, so there is no password to store or rotate.
- Two sizes.
small(Azure Managed RedisBalanced_B0, 0.5 GB) andmedium(Balanced_B1, 1 GB). Withoutspec.sizea new cache gets the default of the environment:smallin test andmediumin prod. Use the cache for caching and short-lived data. See Choose a size.
Prerequisites
- Your application is deployed with Gappynator, so it has a workload identity.
- Your team is onboarded for Azure resources in GAP. If a new cache stays in
AzureProvisioningReady=Falsewith a permission error, contact the platform team.
Create a cache and use it
A Redis is a normal resource next to your Application. The simplest cache has an empty spec, and the only thing you decide is who may use it.
apiVersion: gap.io/v1
kind: Redis
metadata:
name: cache
namespace: team-orders
spec:
access:
- identities:
- name: orders # an Application in the namespace of the Redis
- name: billing # an Application in another namespace
namespace: team-billing
The application only says which cache it connects to:
apiVersion: gap.io/v1
kind: Application
metadata:
name: orders
namespace: team-orders
spec:
image: gjensidige.azurecr.io/team-orders/orders:1.0
port: 8080
redis:
name: cache
# namespace: team-orders # defaults to the namespace of the application
In your manifest repository, add the redis reference to the Application and the Redis next to it in the same list. This is the app.jsonnet from Deploying an Application with the Redis parts added:
local common = import '../common.jsonnet';
local params = import 'params.json';
local application = {
apiVersion: 'gap.io/v1',
kind: 'Application',
metadata: {
name: common.name,
namespace: common.namespace,
labels: common.labels,
},
spec: {
image: params.container_image,
port: common.port,
redis: { name: 'cache' },
},
};
local redis = {
apiVersion: 'gap.io/v1',
kind: 'Redis',
metadata: {
name: 'cache',
namespace: common.namespace,
},
spec: {
access: [
{ identities: [{ name: common.name }] },
],
},
};
{
apiVersion: 'v1',
kind: 'List',
items: [application, redis],
}
Creating the cache takes several minutes. Follow it with kubectl get redis.gap.io -n team-orders. Use redis.gap.io: the short name redis also matches a resource from Azure Service Operator.
Choose a size
spec.size | Azure SKU | Memory | vCPUs | Client connections |
|---|---|---|---|---|
small | Balanced_B0 | 0.5 GB | 2 | 15,000 |
medium | Balanced_B1 | 1 GB | 2 | 15,000 |
Both sizes have high availability. About 20% of the memory is reserved as a buffer, so less than the listed memory is available for your data. Azure advises to scale up when the used memory stays above 75%, watch the Used Memory Percentage metric of the cache. small costs about half of medium, see the Azure Managed Redis pricing.
Most caches use far less than 0.5 GB: in our measurements of existing caches in GAP, most stayed below 200 MB. Start with small if you are unsure, and scale up when you need more.
spec:
size: medium
- No
spec.size. A new cache gets the default of the environment, and an existing cache keeps its size when you remove the field or when the default changes. - Scaling up. Set a larger size, for example
smalltomedium. The cache keeps its name and hostname and is scaled in place, not recreated. According to Microsoft, the data is kept and the cache stays available, but connections can drop briefly and the IP address behind the hostname can change, so your client must reconnect and retry (see Resilience). TheRedisis not ready until Azure has finished, typically 10 to 15 minutes. Do it when the load is low. Gappynator reports aScalingUpevent. - Scaling down is not supported. A smaller size than the current one is not applied: the cache keeps its size,
status.sizeshows it and theRedisEnterpriseReadycondition has the reasonSizeChangeRejected. To get a smaller cache, create a newRedis, move your data and delete the old one.
kubectl get redis.gap.io shows the actual size of the cache.
How access works
Access is owned by the Redis, not by the application.
- The
Redislists who may use it. Every application that should use the cache is listed inspec.access, also the ones in the namespace of theRedis. An application in another namespace is listed with itsnamespace. spec.redison theApplicationonly points at the cache. It does not grant anything, so an application cannot give itself access. If it is not listed,RedisAccessReadyisFalsewith the reasonNotAuthorized, and nothing is granted.- What a listed application gets. The workload identity of the application gets the
defaultdata access policy on the cache, and the generated network policy allows the application to reach the cache. - Revoking. Remove the application from
spec.access, or delete the application, and the access is removed within seconds. A new identity of the application replaces the old access. - The
defaultpolicy is broad (read, write and configure on all keys), and Azure supports no other policy today. Share a cache only between applications that trust each other.
Connection details
A listed application gets two environment variables:
| Variable | Value |
|---|---|
GAPPYNATOR_REDIS_HOST | The hostname of the cache |
GAPPYNATOR_REDIS_PORT | The port of the cache |
They are defined before spec.env, so you can reference them as $(GAPPYNATOR_REDIS_HOST). A variable that you define yourself is not replaced.
The values are added when the cache is ready, which rolls the application once. After that they do not change because of a problem with the cache: an outage, maintenance or a failing provisioning leaves your Deployment untouched. They change only when the cache itself is replaced, and they are removed when the application is no longer listed or no longer references the cache.
Authenticate with Entra ID
Use the workload identity of your application, the same one you use for other Azure resources.
- Acquire a token for the scope
https://redis.azure.com/.default. - Connect with TLS. The user name is the object id of the identity of your application, and the password is the token.
- Refresh the token before it expires and send
AUTHagain on the open connections. Client libraries with Entra support do this for you, for example Microsoft.Azure.StackExchangeRedis for .NET, and the samples for redis-py, Jedis, Lettuce, node-redis and go-redis in Microsoft's guide.
The object id is in the ConfigMap that gappynator keeps next to your application:
kubectl get configmap aso-orders -n team-orders -o jsonpath='{.data.principalId}'
Resilience
The hostname stays the same through failover and maintenance, but open connections are dropped. Your client has to cope with that, gappynator does not restart your application for it.
- Retry commands with exponential backoff and let the client reconnect on its own.
- Use a connect timeout of about 5 seconds, and spread out reconnects after an outage.
- Set a keepalive below the 10 minute idle timeout of the cache.
- Do not check the cache in your readiness probe: a short problem with Redis would otherwise take every pod out of service.
See Best practices for connection resilience from Microsoft.
Status and troubleshooting
kubectl get redis.gap.io -n team-orders
kubectl describe redis.gap.io cache -n team-orders
kubectl get application orders -n team-orders -o jsonpath='{.status.conditions[?(@.type=="RedisAccessReady")]}'
Redis.status.access shows the state for every listed application, and the application reports the outcome in the RedisAccessReady condition. A failing application never makes the cache itself not ready.
| Reason | Meaning |
|---|---|
AccessGranted | The identity has access. |
NotAuthorized | The Redis does not list the application in spec.access. |
RedisNotFound | spec.redis points at a cache that does not exist. |
WaitingForIdentity | The workload identity of the application is not ready yet. |
WaitingForAzure | The access is being created in Azure. |
RevokingAccess | The access is being removed. |
If an application is granted but cannot connect, check that the token is requested for the scope above and that the user name is the object id of the identity. If that does not help, contact the platform team.
Things to know
- Deleting a
Redisdeletes the cache, including its data. - A larger
spec.sizescales the cache up, a smaller one is not applied, see Choose a size. - Each cache costs money while it exists, delete the ones you do not use.