Kubernetes Agent with MS Powershell
In this section, we will walk you through how you can install the Kubernetes agent using the Microsoft PowerShell scripts. You have two installation methods to choose from. You can either go with Helm or manifest files. Along with additional troubleshooting steps, we intend to give you the easiest installation solution possible.
This guide assumes that you have already installed kubectl on your machine.
Prerequisites
1 Kubernetes version
You are required to have Kubernetes version ≥ 1.21, which can be verified using the following command:
1kubectl version
2 Kubernetes Access
kubectl ≥ v1.17.0 configured against your target cluster, which can be verified with the following:
1kubectl version --client3 CLI Tools
Helm v3.5+ (if using Helm) or a shell with bash, curl, and wget installed.
Installation
1 Set Environment Variables
The first and the most important step is to set environment variables containing your API key and target, which will be later used by the installation script.
To do so, first open your terminal and execute the following command, changing the values of MW_API_KEY and MW_TARGET with your credentials:
1$env:MW_API_KEY="<MW_API_KEY>"
2
3 $env:MW_TARGET = 'https://<MW_UID>.middleware.io:443'2 Set Environment Variable for Helm (Only needed if you want Helm installation)
Make sure you have installed Helm in your environment before proceeding.
If you want to use Helm to install the agent instead of batch files, then you need to setup an environment variable.
It is important to note that once you set this variable and execute the script, Helm will be used. If you want to revert, you need to unset the environment variable and reinstall the agent.
To set the environment variable, execute the following command:
1$env:MW_KUBE_AGENT_INSTALL_METHOD='helm'3 Install the Agent
In this step, we will download the script and execute it. You have two options to download the script. You can either download the script manually from our GitHub repository or you can use the cURL command to download the script directly from your terminal.
To download the script via the cURL method, execute the following:
1curl -o mw-kube-agent-install-powershell.ps1 https://raw.githubusercontent.com/middleware-labs/install.middleware.io/refs/heads/master/scripts/mw-kube-agent-install-powershell.ps1Finally, execute the following command to install the agent on your system:
1.\mw-kube-agent-install-powershell.ps1Troubleshooting: Running scripts is disabled on this system
When you execute the script to install the agent, the system might throw you an error message saying “File cannot be loaded because running scripts is disabled on this system”. While there are multiple ways you can solve this issue, it is not recommended to remove the barrier configured by your system for every script you encounter on the system. So the best option is to uplift the barrier just for selective scripts.
To solve this issue, you can change the execution policy, which will prompt for permission every time you execute a third-party script:
1Set-ExecutionPolicy RemoteSigned
Uninstall
If you wish to remove the agent from your system, you first have to download the uninstallation script. The script can be downloaded from our GitHub or cURL.
To download the script via cURL, use the following:
1curl -o mw-kube-agent-uninstall-powershell.ps1 https://raw.githubusercontent.com/middleware-labs/install.middleware.io/refs/heads/master/scripts/mw-kube-agent-uninstall-powershell.ps1Once downloaded, execute the script for removal:
1.\mw-kube-agent-uninstall-powershell.ps1Need assistance or want to learn more about Middleware? Contact our support team at [email protected] or join our Slack channel.