Enable High Availability in MATLAB Online Server
MATLAB® Online Server™ is deployed as a collection of microservices on a Kubernetes® cluster. Because these services are stateless, maintaining state through cookies and communicating with each other, all their data is stored in memory and not backed up. If a pod restarts or fails, MATLAB users might need to sign in again. To prevent this behavior, you can enable high availability (HA) for the server.
In an HA environment, MATLAB Online Server replicates each pod running an individual service. If one pod fails, the server switches to a replicated pod to keep the server running. This improved reliability comes at the expense of using additional computing resources.
Although you can enable HA for MATLAB Online Server regardless of the underlying Kubernetes infrastructure, your production environment should have a highly available Kubernetes cluster. For information on creating a highly available cluster, see the Kubernetes documentation for your provider.
How Services Work in High Availability Environment
MATLAB Online Server runs these core services:
AuthNZ
— AuthenticationCore-UI
— UI-related filesGateway
— Proxies the requests to the appropriate resourceMATLAB Pool
— Remote MATLAB resourcesResource
— Acquires the MATLAB resource for the user
Although MATLAB
Online Server services are stateless, by default the AuthNZ
and
Gateway
services store in-memory information about logged-in users and
the mapping between user sessions and their respective MATLAB instances. When HA is enabled, for these services, MATLAB
Online Server starts four pods (two AuthNZ
pods, two
Gateway
pods) of a Redis™ service that works as a highly available cache. In this configuration, a failure
of a single AuthNZ
or Gateway
pod does not affect stored
information about current sessions and their mapped tokens and MATLAB instances. When a Kubernetes cluster has multiple worker nodes, MATLAB
Online Server pods are configured to be spread across several nodes using
anti-affinity.
Note
High availability does not affect the persistence of MATLAB code and data that users write, store, and execute on the server. To enable users to save data between session, you can mount persistent, individualized folders for them. For details, see Configure File Storage for Users in MATLAB Online Server.
Because the core services start as single pods, MATLAB Online Server is not highly available by default. When you enable HA, the server replicates these pods, either in a local Redis cache server or an external Redis server.
Enable High Availability Using Local Redis Cache (Default)
To enable the default HA configuration for MATLAB Online Server, where the server replicates pods in a local Redis cache server, follow these steps.
In the
install.config
file of your MATLAB Online Server installation folder, set theIS_HA_ENABLED
property totrue
. With this setting, the generated overrides for each MATLAB Online Server service have a replica count set to2
.IS_HA_ENABLED=true
Copy the Helm® charts to add the Redis pod to the updated MATLAB Online Server configuration.
sudo ./mosadm copy-helm-charts
Generate the new YAML override files, skipping the MATLAB image.
sudo ./mosadm generate-overrides --skip-matlab-image
Undeploy and redeploy the server.
./mosadm undeploy
./mosadm deploy
Enable High Availability Using External Redis Server
To use an external Redis server to enable HA, then you must first disable the local Redis deployment and then manually configure the external deployment in the appropriate YAML override files.
In the
install.config
file, setIS_HA_ENABLED
totrue
, and add theDEPLOY_REDIS
property and set it tofalse
.IS_HA_ENABLED=true DEPLOY_REDIS=false
Copy the Helm charts to add the Redis pod to the updated MATLAB Online Server configuration.
sudo ./mosadm copy-helm-charts
Generate the new YAML override files, skipping the MATLAB image.
sudo ./mosadm generate-overrides --skip-matlab-image
(Optional) If you are deploying MATLAB Online Server on Red Hat® OpenShift®, then you must also add the following lines to the generated
./overrides/
file.cluster
/namespace
/redis.yamlserviceAccount: create: false name: "custom-sa"
The
custom-sa
field value is a service account that is created following these instructions for installing MATLAB Online Server on Red Hat OpenShift.oc create sa custom-sa --namespace <namespace-name> oc adm policy add-scc-to-user privileged -z custom-sa --namespace <namespace-name>
Open the
authnz.yaml
andgateway.yaml
override files../overrides/<cluster-name>/<namespace-name>/authnz.yaml
./overrides/<cluster-name>/<namespace-name>/gateway.yaml
In these files, locate the
kv
section. The defaultkv
section enables MATLAB Online Server to generate a Redis configuration with the typeFailoverRedis
in those two files.kv: type: "FailoverRedis" failoverredis: mastername: "redis-sentinel-master" addrs: "mathworks-redis:26379"
The
FailoverRedis
cache type enables communication with the Redis server deployed within MATLAB Online Server, using the configuration specified underfailoverredis
.Update the cache type and configuration for your external Redis server. Specify one of these configurations.
BasicRedis
— Single Redis instance, where all items are stored in the same instance.kv: type: "BasicRedis" basicredis: addr: "your-redis-server:your-redis-port" tls: true password: "your-redis-password"
ClusterRedis
— Multiple Redis instances, where items are sharded across all instances and each instance has only a subset of items.kv: type: "ClusterRedis" clusterredis: addrs: "your-redis-server:your-redis-port" tls: true password: "your-redis-password"
The
addrs
field, under theClusterRedis
type, can be assigned to a singleserver:port
value or to multiple comma-separatedserver-i:port-i
values.
Note
Not all Redis configurations provided by cloud platforms support HA by default. If you are using an external Redis server, use one with an HA configuration enabled. For secure communication with any external Redis server, you must set the
tls
field totrue
.To apply your changes, undeploy and redeploy the server.
./mosadm undeploy
./mosadm deploy