DevSecOps for BBK
  • Introduction
  • Getting Started
    • Virtual Training Practices
    • Training Plan
    • Tools and Configuration
    • Troubleshooting
  • Docker Fundamentals
    • Docker Setup
    • Docker First Container
    • Docker Network Basics
    • Docker Network Exercise
    • Docker Volume Basics
    • Docker Storage
  • Dockerfile Fundamentals
    • Dockerfile Instructions
    • Dockerfile Environment Variables
    • Dockerfile Build Arguments
    • Non-privileged Containers
    • Dockerfile Order of Execution
    • Dockerfile Volume
    • Entrypoint Command
    • Multiple Stage Build
  • Container Management
    • Containers Start Automatically
  • Docker Security
    • Seccomp Profile
  • Docker Compose
    • Docker Compose Install
    • Docker Compose Commands
    • Docker Compose File
    • Docker Compose Volumes and Network
  • K8s Cluster Setup
    • Minikube Installation
    • Calico Networking
    • K8s Walkthrough
    • K8s Cheat Sheet
  • Understand K8s
    • Pod Connectivity
    • Deployments
    • Service Cluster IP
    • Service NodePort
    • ClusterIP Exercise
    • NodePort Exercise
    • Service LoadBalancer
    • Configmap
    • Secrets
  • Application Lifecycle Management
    • Rolling Updates and Rollback
    • Multi Container Pod
  • K8s Storage
    • Persistent Volume
    • Persistent Volume Claim
    • PVC in POD
  • Istio
    • AKS Setup
    • Kubectl Setup in Windows
    • Istio Setup Manual
    • Istio Demo App
    • Istio Observability
  • Terraform
    • Terraform Setup
    • Terraform Demo
    • Azure Terraform Setup
  • Terraform AWS
    • Terraform AWS Setup
    • Terraform AWS Demo S3
  • Refrences
    • Docker Static Site
    • Docker First Image
Powered by GitBook
On this page
  • 1. Create a folder to contain your Kubernetes tools
  • 2. Add the folder location to the Windows PATH environment variable
  • 3. Download the kubectl command
  • 4. Create the .kube directory
  • 5. Create the Windows kubectl kubeconfig file
  • 6. Change the API version listed in the kubeconfig file
  • 7. Verify connectivity to the Kubernetes cluster
  1. Istio

Kubectl Setup in Windows

PreviousAKS SetupNextIstio Setup Manual

Last updated 2 years ago

To install kubectl on Windows and create the kubeconfig file, it will generally involve the following steps:

  1. Create a folder to contain your Kubernetes tools

  2. Add the folder location to the Windows PATH environment variable

  3. Download the kubectl command

  4. Create the .kube directory

  5. Create the Windows kubectl kubeconfig file

  6. Change the API version listed in the kubeconfig file

  7. Verify connectivity to the Kubernetes cluster

1. Create a folder to contain your Kubernetes tools

I like to create a folder that will house the tools used for Kubernetes. Many of these tools are self-contained executables that you can run from any directory. Examples include kubectl and helm. I like to create a directory called “KubeTools” which house all the tools I use for interacting with Kubernetes. This way, you just add one folder to your Windows PATH variable and you are good to go for any Kubernetes tool you place in the folder.

2. Add the folder location to the Windows PATH environment variable

3. Download the kubectl command

After you have the folder in place and the directory in the PATH statement, you can download the kubectl command to your directory. To do you that, you run the CURL command below. Yes curl works in Windows 10.

curl -LO https://dl.k8s.io/release/v1.21.0/bin/windows/amd64/kubectl.exe

After you have configured the PATH statement and downloaded the kubectl command, run the kubectl command to verify you see the return from the command with the available parameters. This verifies the PATH statement is working as expected.

4. Create the .kube directory

Now that we have the kubectl utility downloaded and the Windows PATH statement in place to run the command from any command-line context, we need to create the directory the command looks to for the configuration. Kubectl looks at the path:

$HOME/.kube

For Windows, this is the root of your %USERPROFILE% directory of the user that will be running the kubectl command. All you need to do is create the “.kube” directory in this directory.

5. Create the Windows kubectl kubeconfig file

6. Change the API version listed in the kubeconfig file

One little issue I ran into after copying down the kubeconfig file to the %userprofile%/.kube directory was the API version listed in the file errored out. Below is the error received.

In looking at the kubeconfig file, it was indeed set to apiVersion: v0. I simply changed this to v1 and it resolved the issue.

7. Verify connectivity to the Kubernetes cluster

The last step is verifying connectivity to the Kubernetes cluster. After changing the API version in the kubeconfig file to v1, as you can see below, after getting the error we can now connect to the Kubernetes cluster and get pods.

After you have created the folder, add the folder to the PATH environment variable. This makes it so you don’t have to navigate to the literal path of kubectl to run the command. You can simply type in the kubectl command from any command line context.

Docker Desktop for Windows adds its own version of kubectl to the Windows PATH. If you have installed Docker Desktop, you may need to place your PATH entry before the one added by the Docker Desktop installer or remove the Docker Desktop’s kubectl.

Downloading the kubectl command using curl in windows 10
Running the kubectl command to verify windows path and other configuration
Create the kube directory in your windows userprofile directory

Since the .kube directory is created, we now need to create the kubeconfig file that is needed for the kubectl command. The kubeconfig file contains the configuration needed to tell kubectl how to connect to the Kubernetes cluster. An easy way to “create” this file is simply copy the file that is generated on your hosts using the kubeadm command.

Error loading config file api version
Change from v0 to v1 in the kubeconfig file from your kubernetes master node
The kubectl command is verified and is able to connect to the remote kubernetes cluster
Windows
***As a note***
Kubernetes
Make a windows folder to house kubectl
Add the directory to your windows path statement
Copying over the kubeconfig file from your kubernetes cluster
After copying the admin.conf file to config under the kube directory in the user profile