Step by Step Kubernetes implementation on Windows

A couple of months back, a friend of mine was facing an issue when it came to installing Kubernetes on Windows and honestly it took me some time to get things right. Thought I should share this in a blogpost so that others can also benefit and do not end up messing things.

Step 1: Install Docker Desktop

Kubernetes requires Docker to be installed on your system. You can download and install Docker Desktop from the Docker website.

Step 2: Enable Kubernetes in Docker Desktop

Once Docker Desktop is installed, enable Kubernetes by going to the Docker Desktop settings and checking the “Enable Kubernetes” option.

Step 3: Install kubectl

kubectl is a command-line tool for interacting with Kubernetes. You can download and install kubectl from the Kubernetes website.

Step 4: Create a Kubernetes cluster

To create a Kubernetes cluster on your local machine, open a terminal and run the following command:

kubectl config use-context docker-for-desktop

This command sets up kubectl to use the Docker Desktop Kubernetes cluster.

Step 5: Deploy an application

To deploy an application to your Kubernetes cluster, create a deployment YAML file. Here is an example YAML file which you can edit and use:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: example-deployment
spec:
  selector:
    matchLabels:
      app: example-app
  replicas: 1
  template:
    metadata:
      labels:
        app: example-app
    spec:
      containers:
        - name: example-container
          image: nginx:latest
          ports:
            - containerPort: 80

This YAML file creates a deployment for an nginx container. To deploy the application, run the following command:

kubectl apply -f example-deployment.yaml

This command creates the deployment and starts the nginx container.

Step 6: Expose the Deployment

To access the nginx container, you need to expose the deployment as a service. Here is an example YAML file for creating a service:

apiVersion: v1
kind: Service
metadata:
  name: example-service
spec:
  selector:
    app: example-app
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
  type: NodePort

This YAML file creates a service that exposes the nginx container on port 80. To create the service, run the following command:

kubectl apply -f example-service.yaml

This command creates the service and exposes the nginx container.

Step 7: Access the Application

To access the nginx container, get the IP address of the Kubernetes cluster by running the following command:

kubectl get nodes -o wide

This command returns the IP address of the Kubernetes cluster. To access the nginx container, open a web browser and enter the following URL:

http://<node-ip-address>:<node-port>

Replace with the IP address of the Kubernetes cluster and with the port number assigned to the nginx container by the service.

That’s it! You have successfully implemented Kubernetes on Windows and deployed an application to a Kubernetes cluster.

Leave a Reply