Using Amazon Elastic Container Service for Kubernetes (EKS) on Windows 10
At CenterEdge Software, we currently operate our Kubernetes clusters on AWS. We manage the clusters ourselves, using the kops tool. Unfortunately, managing your own Kubernetes cluster adds a lot of overhead.
Therefore, I recently embarked on a proof of concept using Amazon Elastic Container Service for Kubernetes, a.k.a. EKS. I quickly found that a significant friction point in this process was my Windows 10 laptop, which is a problem since CenterEdge Software is a Microsoft shop.
Below I share some of the steps I found that helped along the way. I won’t cover setting up the EKS cluster itself, I’ll let the AWS documentation handle that.
Prerequisites
-
Install kubectl and the AWS CLI. I used Chocolatey to install both.
choco install -y kubernetes-cli choco install -y awscli
-
Configure AWS CLI with your credentials
aws configure
Setting Up AWS IAM Authenticator
When using EKS, kubectl must be configured to use the AWS IAM Authenticator. This lightweight utility is called by kubectl to get authentication tokens, and uses your credentials configured for the AWS CLI. It can support IAM roles and multiple profiles, but for this example I’ll keep it simple and assume we’re using the default profile configured via aws configure
.
- Download the authenticator. The current URL for Windows is https://amazon-eks.s3-us-west-2.amazonaws.com/1.11.5/2018-12-06/bin/windows/amd64/aws-iam-authenticator.exe, but you may want to find the up-to-date version here.
- Place aws-iam-authenticator.exe somewhere in your system path. For example, I was lazy and put it in C:\ProgramData\Chocolatey\bin.
- Right-click on aws-iam-authenticator.exe, select Properties, and Unblock the file so it can be executed.
-
Confirm that the command is working from a new shell window:
aws-iam-authenticator --help
Update: I updated some of the links above, and here is a script to download aws-iam-authenticator and add it to your path:
$installDir = "${env:LOCALAPPDATA}\aws-iam-authenticator"
$version = "1.11.5/2018-12-06"
New-Item -ItemType Directory $installDir -ErrorAction SilentlyContinue
Invoke-WebRequest -OutFile $installDir\aws-iam-authenticator.exe -UseBasicParsing "https://amazon-eks.s3-us-west-2.amazonaws.com/$version/bin/windows/amd64/aws-iam-authenticator.exe"
Unblock-File $installDir\aws-iam-authenticator.exe
$path = [Environment]::GetEnvironmentVariable("PATH", [EnvironmentVariableTarget]::User) -split ";"
if ($path -inotcontains $installDir) {
$path += $installDir
[Environment]::SetEnvironmentVariable("PATH", $path -join ";", [EnvironmentVariableTarget]::User)
$env:PATH = (([Environment]::GetEnvironmentVariable("PATH", [EnvironmentVariableTarget]::Machine) -split ";") + $path) -join ";"
}
Adding Your Cluster To Your Kubernetes Config
The easiest way to add your cluster to your Kubernetes configuration is using the AWS CLI. It’s also possible to keep multiple configuration files, but I prefer having multiple contexts inside my default configuration file.
# Substitute "brant" below with the name of your EKS cluster
aws eks update-kubeconfig --name brant
However, after this is complete I recommend changing the name of the created context to be more usable. The first parameter below is the name of the context output by the update-kubeconfig command. The second is the new name.
kubectl config rename-context arn:aws:eks:us-east-1:000000000000:cluster/brant brant
Finally, test it out!
kubectl get svc
Working From Ubuntu on Windows using WSL
Unfortunately, many tools you may wish to use are Linux tools and don’t work well from Windows. An easy solution is to install Ubuntu on Windows 10. However, making your previous configuration for EKS work in Ubuntu requires a few more steps.
- Install [kubectl]https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-kubectl-binary-using-native-package-management) in Ubuntu.
-
Add a KUBECONFIG environment variable to your Windows user profile (alter the path below if needed):
setx KUBECONFIG ${env:USERPROFILE}\.kube\config
-
Configure WSL to pass KUBECONFIG into Ubuntu, while remapping the path:
# WSLENV is a colon-separated list of environment variables to copy to Ubuntu from your Windows Profile # Appending "/p" to the variable name tells WSL that the variable is a path, and to remap the path to the Ubuntu path when it's copied setx WSLENV $($(if ([System.String]::IsNullOrWhitespace(${env:WSLENV})) { "" } else { ${env:WSLENV} + ":"}) + "KUBECONFIG/p")
- Restart Ubuntu
-
Test it out. Kubectl will run in Ubuntu, which in turn executes the Windows aws-iam-authenticator.exe process to get the authentication token.
kubectl get svc
Conclusion
At this point, you should have complete access to your EKS cluster via kubectl from both Powershell and Ubuntu Bash. Now the real fun can begin!
Comments