Running mabl Link on Kubernetes
You can easily run mabl Link on a Kubernetes cluster, simplifying your testing infrastructure. By using the mabl Link with Docker image, concerns over runtime compatibility, configuration, and provisioning are eliminated.
Kubectl
Link Agent Pod Via Command Line
Use kubectl to run the Link Agent in your Kubernetes cluster:
$ kubectl run mabl-link-agent\
--namespace=<YOUR-NAMESPACE>\
--image=mablhq/link-agent\
-- --api-key <MABL-LINK-API-KEY> --name <LINK-AGENT-NAME>
NOTE: The bare
--
is not a typo.This is necessary for
kubectl
.
Link Agent Pod from YAML spec file
Kubernetes configurations are often stored in YAML form. For example, you can include the mablhq/link-agent
image inside a Pod or Deployment spec. A basic pod spec defined in a YAML file is:
- replace
<YOUR-NAMESPACE>
with your Kubernetes namespace - replace
<MABL-LINK-API-KEY>
with your mabl API key - replace
<LINK-AGENT-NAME>
with your Link Agent name (arbitrary)
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>
Now run the following kubectl
command to launch a Link Agent on your Kubernetes cluster.
$ 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, you can stop the Link Agent using:
$ kubectl delete pod mabl-link-agent -n <YOUR-NAMESPACE>
Shutdown button and Kubernetes Link Agents
If you click the Shutdown button on the Settings > Networking > mabl Link Agents mabl web app screen, it will have no overall effect. Kubernetes deployments will try to always maintain a set number of replicas, so while the Link Agent you clicked Shutdown for will terminate, the deployment will spawn a replacement Link Agent within seconds, effectively preventing termination of that Link Agent tunnel. Similarly, pod based Link Agents will attempt to restart based on their Restart Policy.
To stop a Kubernetes based Link Agent, delete the Kubernetes pod or deployment , use the command
kubectl delete pod mabl-link-agent -n <YOUR-NAMESPACE>
.
Link Agent deployment via YAML spec file
You can also run mabl Link Agents using a Kubernetes Deployment. Deployments allow high availability (HA) setups, by setting a replicas
value > 1 (see spec below). Each new connection from a browser under test will be randomly routed to one of the available Link Agent instances. If a Link Agent dies, only open browser connections will be lost. Subsequent connections will be routed to the remaining active Link Agent instances.
HA Link Agent Pool Limitations
If a Link Agent is running and connected to mabl, it will be considered healthy. However, it is possible this Link Agent cannot successfully route traffic to the desired destinations (e.g. it is running on the wrong host). Such a routing issue would not cause a Link Agent to be ejected from the HA pool. Only failed Link Agents (e.g. process is terminated, stopped, crashed) are removed from the HA pool.
- replace
<YOUR-NAMESPACE>
with your Kubernetes namespace - replace
<MABL-LINK-API-KEY>
with your mabl API key - replace
<LINK-AGENT-NAME>
with your Link Agent name (arbitrary)
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>"
You can create the Link Agent deployment using commands similar to the pod creation commands. If you encounter problems creating a deployment, ensure that you can create a single pod (see above section) to confirm that your configuration values are correct.
$ kubectl create -f mabl-link-agent-deployment.yaml
When done using the Link Agent, you can stop the Link Agent deployment using:
$ kubectl delete deployment mabl-link-agent-deployment -n <YOUR-NAMESPACE>
Link Agent Kubernetes Readiness Probes
Usually Link Agent startup is rapid, but there may sometimes be a delay to spin up new infrastructure for a new Link tunnel. You can use Readiness Probes to notify Kubernetes once your Link Agent pod has successfully established its tunnel.
Update the container section of your Link Agent spec file (see above), to look like the following , with a readinessProbe section.
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
Updated over 1 year ago