Kubernetes
This guide walks you through installing the Infrastructure Agent (Infra Agent) in a Kubernetes environment. These instructions can also be found on the Installation page in the Middleware application.
The installation will set up a DaemonSet inside your Kubernetes cluster and add necessary components to appropriately permission the DaemonSet pods. A Kubernetes service is also created to allow components to connect to the Infra Agent via Cluster IP address and ports (i.e. language-based APMs).
Prerequisites
1 Kubernetes Version
Kubernetes version 21.0.0
or above. Check with the following command:
kubectl version
2 Kubernetes Access
Access to Kubernetes cluster and client (i.e. kubectl)
kubectl
version should be >= v1.17.0
, You can verify the current version via this command
kubectl version --client
3 CLI Tools
Install
Step 1: Access Kubernetes Installation
Log in to Middleware, navigate to the Installation Page in the bottom left corner and select Kubernetes from the Infrastructure section
Step 2: Identify Kubernetes Context
Get the current Kubernetes Context and ensure the cluster belonging to this Context is where you want to install the Infra Agent.
Use the following command to find out your current Kubernetes context:
kubectl config get-contexts `kubectl config current-context`
Step 3: Run Kubernetes Install Command
Install the Infra Agent with Bash, .bat or Helm. Copying the command directly from the Installation page ensures your API key and Target is inserted correctly.
If you are installing the Infra Agent with Microsoft PowerShell, proceed to the Kubernetes with MS PowerShell document.
Step 3a: Install with Bash
MW_API_KEY="<MW_API_KEY>" MW_TARGET=https://<MW_UID>.middleware.io:443 bash -c "$(curl -L https://install.middleware.io/scripts/mw-kube-agent-install-v2.sh)"
Step 3b: Install with .bat
Download the Infra Agent batch file here. Open PowerShell, change the directory to the location of the download, and execute the following commands:
set MW_API_KEY="<MW_API_KEY>" set MW_TARGET=https://<MW_UID>.middleware.io:443 mw-kube-agent-install-windows.bat
Step 3b: Install with Helm
To get started you'll want to add our helm repo and then run the helm install below.
helm repo add middleware-labs https://helm.middleware.io
helm install mw-agent middleware-labs/mw-kube-agent-v2 --set mw.apiKey=<MW_API_KEY> --set mw.target=https://<MW_UID>.middleware.io:443
Using an existing secret w/ Helm to manage API Keys
You can use an existing secret from your secret manager with the below snippet, assuming that secret has the Middleware API Key:
mw: target: https://<MW_UID>.middleware.io:443 apiKeyFromExistingSecret: enabled: true name: name-of-your-secret key: name-of-your-secret-key clusterMetadata: name: my-cluster
Step 4: Add Host Tags [Optional]
Create filterable custom tags by adding the MW_HOST_TAGS
environment variable to the installation command as comma-separated key-value pairs. Use the tag name
to create an alias for the host (e.g. production).
Check your host tags have been embedded by navigating to Infrastructure -> Your Desired Host -> System Information
MW_HOST_TAGS=key1:value1,key2:value2,... MW_API_KEY="<MW_API_KEY>"
Step 5: Verify Installation
Verify the status of the Infra Agent with the following command:
kubectl get daemonset/mw-kube-agent -n mw-agent-ns
Step 6: Check Your Dashboard
Navigate to Middleware and ensure metrics are appearing in the Unified Dashboard. Depending on the size of your cluster, it can take up to a few minutes for metrics to appear. If metrics do not appear after this time head to our troubleshooting page for some common issues.
Upgrade
The Infra Agent is frequently updated to add new features and improve performance. More information on new features can be found in our Newsletter.
To upgrade Infra Agent, use the following command:
bash -c "$(curl -L https://install.middleware.io/scripts/mw-kube-agent-upgrade.sh)"
Troubleshooting
Run only one Infra Agent DaemonSet per cluster per host. Multiple agents will cause unexpected behavior.
Once the Infra Agent is installed on your cluster metrics should begin appearing in the Middleware application within a few minutes. If metrics do not appear, confirm that Kubernetes has access to the internet, either directly or through a proxy, and that only one MW Agent is running per cluster.
Switching Between Contexts
If you are using another thirdy-party resource for managing your Kubernetes Infrastructure (e.g. Lens) it's possible your cluster names are similar across clusters. This will make it hard to delineate between the clusters inside of Middleware.
To fix this, you can force a speicific cluster.name
by setting the MW_KUBE_CLUSTER_NAME
environment variable to the name(s) you are using in your thrid party resource. Once the cluster is renamed, it will automatically reset and start to catch the appropriately labeled environment variables.
Uninstall
To uninstall the Infra Agent use the following command:
bash -c "$(curl -L https://install.middleware.io/scripts/mw-kube-agent-uninstall-v2.sh)"
If you installed the agent via Helm chart, you can uninstall via the following command:
helm uninstall mw-agent
Need assistance or want to learn more about Middleware? Contact our support team in Slack.