Debug School

Cover image for Kubernetes Setup
Suyash Sambhare
Suyash Sambhare

Posted on

Kubernetes Setup

Install and configure Kubernetes on both Windows and Ubuntu

On Windows

  1. Install Docker Desktop:

    • Download Docker Desktop from the official Docker website.
    • Run the installer and follow the on-screen instructions.
  2. Install kubectl:

    • Open PowerShell as an administrator.
    • Run the following command to download kubectl:
     curl.exe -LO "https://dl.k8s.io/release/v1.31.0/bin/windows/amd64/kubectl.exe"
    
  • Validate the binary (optional):

     curl.exe -LO "https://dl.k8s.io/release/v1.31.0/bin/windows/amd64/kubectl.exe.sha256"
     CertUtil -hashfile kubectl.exe SHA256
     type kubectl.exe.sha256
    
  • Move the binary to a directory in your PATH:

     mkdir -p $HOME/bin
     mv .\kubectl.exe $HOME\bin\kubectl.exe
    
  • Add the directory to your PATH environment variable.

  1. Install Minikube:

  2. Start Minikube:

    • Open a new command prompt and run:
     minikube start
    

On Ubuntu

  1. Update the package list and install dependencies:
   sudo apt-get update
   sudo apt-get install -y apt-transport-https ca-certificates curl
Enter fullscreen mode Exit fullscreen mode
  1. Download the Google Cloud public signing key:
   curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
Enter fullscreen mode Exit fullscreen mode
  1. Add the Kubernetes APT repository:
   sudo bash -c 'cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
   deb https://apt.kubernetes.io/ kubernetes-xenial main
   EOF'
Enter fullscreen mode Exit fullscreen mode
  1. Install Kubernetes components:
   sudo apt-get update
   sudo apt-get install -y kubelet kubeadm kubectl
   sudo apt-mark hold kubelet kubeadm kubectl
Enter fullscreen mode Exit fullscreen mode
  1. Initialize the Kubernetes cluster:
   sudo kubeadm init
Enter fullscreen mode Exit fullscreen mode
  1. Set up the local kubeconfig:
   mkdir -p $HOME/.kube
   sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
   sudo chown $(id -u):$(id -g) $HOME/.kube/config
Enter fullscreen mode Exit fullscreen mode
  1. Install a pod network add-on (e.g., Calico):
   kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
Enter fullscreen mode Exit fullscreen mode
  1. Join worker nodes to the cluster:
    • Run the kubeadm join command provided at the end of the kubeadm init output on each worker node.

These steps should get you up and running with Kubernetes on both Windows and Ubuntu.

Kubernetes

Deploy an application on Kubernetes

This involves several steps. Here's a general guide to help you get started:

1. Create a Deployment YAML File

First, you need to define your application in a YAML file. This file will describe the desired state of your application, including the container image, number of replicas, and other configurations.

Here's an example of a simple deployment YAML file:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
      - name: my-app-container
        image: my-app-image:latest
        ports:
        - containerPort: 80
Enter fullscreen mode Exit fullscreen mode

2. Apply the Deployment

Use the kubectl apply command to create the deployment in your Kubernetes cluster:

kubectl apply -f my-app-deployment.yaml
Enter fullscreen mode Exit fullscreen mode

3. Expose the Deployment

To make your application accessible, you need to expose it using a Service. Here's an example of a Service YAML file:

apiVersion: v1
kind: Service
metadata:
  name: my-app-service
spec:
  selector:
    app: my-app
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
  type: LoadBalancer
Enter fullscreen mode Exit fullscreen mode

Apply the Service configuration:

kubectl apply -f my-app-service.yaml
Enter fullscreen mode Exit fullscreen mode

4. Verify the Deployment

Check the status of your deployment and service:

kubectl get deployments
kubectl get services
Enter fullscreen mode Exit fullscreen mode

5. Access Your Application

If you used a LoadBalancer type service, you can access your application using the external IP address provided by the service. You can find this IP address by running:

kubectl get services my-app-service
Enter fullscreen mode Exit fullscreen mode

Additional Tips

  • Scaling: You can scale your application by updating the replicas field in your deployment YAML file and reapplying it.
  • Updating: To update your application, modify the container image in the deployment YAML file and apply the changes.
  • Monitoring: Use kubectl logs and kubectl describe to troubleshoot and monitor your application.

Ref: https://kubernetes.io/docs/setup/

Top comments (0)