How to Install kubectl and Minikube on Ubuntu Machine: A Step-by-Step Guide

How to Install kubectl and Minikube on Ubuntu Machine: A Step-by-Step Guide

·

4 min read

Kubernetes is one of the most popular platforms for orchestrating containerized applications. Minikube allows developers to run Kubernetes clusters locally, providing an excellent environment for testing and development. kubectl, the command-line tool for interacting with Kubernetes, is essential for managing your clusters and resources.

In this blog, we'll walk through the steps to install kubectl and Minikube on an Ubuntu machine. By the end of this guide, you'll have a fully working local Kubernetes cluster for development.


Step 1: Install kubectl on Ubuntu

What is kubectl?

kubectl is the Kubernetes command-line tool used to interact with Kubernetes clusters. It allows you to deploy applications, inspect cluster resources, and manage configurations.

Install kubectl via apt repository:

  1. Update the apt package index: Open your terminal and run the following command to update the local package index:

     sudo apt-get update
    
  2. Install required dependencies: Install apt-transport-https and ca-certificates, which are required to fetch the Kubernetes package:

     sudo apt-get install -y apt-transport-https ca-certificates curl
    
  3. Add the Google Cloud public signing key: To install kubectl from the Kubernetes repository, add the official Google Cloud key to your apt keyring:

     curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
    
  4. Add the Kubernetes apt repository: Add the Kubernetes repository to your apt sources list:

     sudo apt-add-repository "deb https://apt.kubernetes.io/ kubernetes-xenial main"
    
  5. Install kubectl: Now, install kubectl with the following command:

     sudo apt-get update
     sudo apt-get install -y kubectl
    
  6. Verify kubectl installation: After the installation is complete, verify the installation by checking the version:

     kubectl version --client
    

    This should display the installed version of kubectl.


Step 2: Install Minikube on Ubuntu

What is Minikube?

Minikube is a tool that runs a single-node Kubernetes cluster locally on your machine. It’s perfect for learning Kubernetes, developing apps, or testing configurations without needing a cloud-based Kubernetes cluster.

Install Minikube via apt repository:

  1. Install dependencies: You’ll need curl, wget, and virtualbox (or another hypervisor like KVM or docker) for Minikube to work:

     sudo apt-get install -y curl wget virtualbox
    
  2. Download the Minikube binary: Minikube provides a .deb package for Ubuntu, but it’s generally better to install using a direct curl command to ensure you get the latest version:

     curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
    
  3. Install Minikube: After downloading, move the Minikube binary to /usr/local/bin:

     sudo mv minikube-linux-amd64 /usr/local/bin/minikube
    
  4. Verify Minikube installation: Check the Minikube version to confirm that the installation was successful:

     minikube version
    

Step 3: Start a Minikube Cluster

Now that you’ve installed both kubectl and Minikube, you can start your local Kubernetes cluster.

  1. Start Minikube: To start your Minikube Kubernetes cluster, run:

     minikube start
    

    Minikube will download the necessary images and set up a virtual machine with a single-node Kubernetes cluster.

  2. Check the status: To ensure your cluster is running, use:

     minikube status
    
  3. Configure kubectl to use the Minikube cluster: Minikube automatically configures kubectl to interact with your Minikube cluster, but you can verify it by running:

     kubectl config use-context minikube
    
  4. Access the Minikube Dashboard: Minikube provides a Kubernetes dashboard for a more visual way to manage your cluster. To launch the dashboard, run:

     minikube dashboard
    

    This command will open the Kubernetes Dashboard in your browser.


Step 4: Verify the Installation

Check kubectl connectivity:

To check if your kubectl can successfully communicate with the Minikube cluster, run:

kubectl cluster-info

This should display information about the cluster and confirm that kubectl is connected to your Minikube instance.

Get a list of Pods:

To verify that everything is up and running, list the pods running in the Minikube cluster:

kubectl get pods --all-namespaces

Conclusion

With Minikube and kubectl installed on your Ubuntu machine, you now have a local Kubernetes cluster for development and testing. This setup is perfect for learning Kubernetes concepts, testing applications, or experimenting with Kubernetes configurations without needing a cloud-based cluster.

You can continue learning more by deploying your applications or setting up Helm, the Kubernetes package manager, to streamline your app deployments.

Feel free to explore more Kubernetes tools and tutorials, and enjoy your journey with container orchestration!


Useful Links: