Running mabl Link on a Kubernetes cluster simplifies your testing infrastructure. Jobs deployed to Kubernetes automatically pull the mabl Link Docker image, which eliminates concerns over runtime compatibility, configuration, and provisioning.
Read on for detailed instructions on setting up the Link Agent in a Kubernetes cluster.
Before you start
Before you start, gather the following necessary information:
- "Link Agent" API key. API key access is limited to workspace owners.
- The name of your Kubernetes namespace
Run the Link Agent
Running the Link Agent in a Kubernetes cluster requires the following arguments:
<YOUR-NAMESPACE>
- your Kubernetes namespace.<MABL-LINK-API-KEY>
- the "Link Agent" API key that you created in step 1.<LINK-AGENT-NAME>
- create a name for your Link Agent between 1 and 24 characters long that consists of lowercase letters, numbers, and dashes.
Use kubectl to run the Link Agent in your Kubernetes cluster. For example:
$ kubectl run mabl-link-agent\ --namespace=<YOUR-NAMESPACE>\ --image=mablhq/link-agent\ -- --api-key <MABL-LINK-API-KEY> --name <LINK-AGENT-NAME>
The bare --
is not a typo. This is necessary for kubectl
.
Kubernetes configurations are often stored in YAML form. Instead of running kubectl run mabl-link-agent
, you can create a pod to run a single Link Agent or a deployment to run multiple Link Agents in a high availability configuration.
Create a Link Agent pod
The following example is a basic YAML spec for creating a Link Agent pod. Replace <YOUR-NAMESPACE>
, <MABL-LINK-API-KEY>
, and <LINK-AGENT-NAME>
with the appropriate values:
apiVersion: v1 kind: Pod metadata: name: mabl-link-agent namespace: <YOUR-NAMESPACE> spec: containers: - name: mabl-link-agent image: mablhq/link-agent args: - --api-key - <MABL-LINK-API-KEY> - --name - <LINK-AGENT-NAME>
To launch a Link Agent pod from a YAML spec file, run the following command:
$ kubectl create -f mabl-link-agent.yaml # Optionally follow the logs $ kubectl logs -f mabl-link-agent -n <YOUR-NAMESPACE>
When done using the Link Agent, terminate the Link Agent using the following command:
$ kubectl delete pod mabl-link-agent -n <YOUR-NAMESPACE>
Running the Link Agent in high availability setups
You can also run mabl Link Agents using a Kubernetes deployment. Deployments allow high availability (HA) setups by setting a replicas
value > 1. Each new connection from a mabl test is randomly routed to one of the available Link Agent instances.
The following example is a basic YAML spec for creating a Link Agent deployment. Replace <YOUR-NAMESPACE>
, <MABL-LINK-API-KEY>
, and <LINK-AGENT-NAME>
:
apiVersion: apps/v1 kind: Deployment metadata: name: mabl-link-agent-deployment namespace: <YOUR-NAMESPACE> labels: app: mabl-link-agent spec: # Use values > 1 for HA (e.g. 2-3) replicas: 1 selector: matchLabels: app: mabl-link-agent template: metadata: labels: app: mabl-link-agent spec: containers: - name: mabl-link-container image: mablhq/link-agent args: - "--api-key" - "<MABL-LINK-API-KEY>" - "--name" - "<LINK-AGENT-NAME>"
To launch a Link Agent deployment from a YAML spec file, run the following command:
$ kubectl create -f mabl-link-agent-deployment.yaml
If you encounter issues creating a Link Agent deployment, try creating a single Link Agent pod to confirm that your configuration values are correct.
The high availability (HA) Link Agent configuration removes Link Agents that are terminated, stopped, or crashed. If a Link Agent dies, only open connections to mabl tests through that specific Link Agent are lost. Subsequent connections are routed to the remaining active Link Agent instances.
As long as a Link Agent is running and can connect to mabl, it is considered healthy. If you install the Link Agent on a machine that cannot route traffic to the desired destination, the Link Agent will still appear as healthy.
When done using the Link Agent, terminate the Link Agent deployment using the following command:
$ kubectl delete deployment mabl-link-agent-deployment -n <YOUR-NAMESPACE>
Validate the Link connection is live
Usually Link Agent startup is rapid, but there may be a delay to spin up new infrastructure for a new Link Tunnel. Use Readiness Probes to notify Kubernetes once your Link Agent pod has successfully established its tunnel.
Update the container section of your Link Agent YAML spec file to include readinessProbe section, as shown in the following example:
containers: - name: mabl-link-container image: mablhq/link-agent args: - "--api-key" - "<MABL-LINK-API-KEY>" - "--name" - "<LINK-AGENT-NAME>" # Mark pod Ready when successful Link Agent connection established readinessProbe: exec: command: - grep - "-ci" - "connections are active" - /opt/mabl/link-agent/logs/agent.log initialDelaySeconds: 10 periodSeconds: 10
When the tunnel is active, the Link Agent appears with a "Connected" status on the networking page in the mabl app: Settings > Networking.
Next steps
When the Link Agent is installed and running, configure your tests to run over mabl Link.