minikube
ssh
virtual machine
kubernetes
devops

How do I ssh into the VM for Minikube?

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

Minikube is a popular tool that enables you to set up a single-node Kubernetes cluster on your local machine. One interesting task you may want to perform is accessing the underlying virtual machine (VM) where Minikube runs. This can be especially useful for debugging or making custom configurations. This article walks you through the process and addresses technical details of using SSH to connect to a Minikube VM.

Understanding Minikube's Architecture

Before diving into execution, it's crucial to understand Minikube's architecture. Minikube starts a VM or a container based on the driver being used. It supports a variety of drivers such as VirtualBox, Docker, Hyper-V, and others. The choice of driver influences how you can SSH into the VM:

  • VM Driver: If you are using a VM-based driver like VirtualBox or Hyper-V, Minikube sets up a virtual environment running a Linux kernel.
  • Docker Driver: If you are using Docker, Minikube will run a Docker container instead of a full-fledged VM.

The steps to SSH into the VM or the Docker container may differ based on this setup.

Prerequisites

Before attempting to SSH into a Minikube VM, ensure the following:

  1. Minikube installed: You have Minikube installed and running on your system.
  2. VM running: Ensure Minikube is up and running using a minikube start command.
  3. SSH client: You have an SSH client installed on your local machine (most Unix-based systems have it by default).

SSH into Minikube VM

The most straightforward method to log into the VM or container is using Minikube's built-in SSH command. Below are the steps and variations for different drivers.

Step-by-Step Guide

  1. Identify the Driver: Determine the driver you are using with Minikube:
bash
   minikube profile list

This command will list profiles, allowing you to identify the active driver.

  1. SSH with Built-In Command: Minikube comes with a built-in SSH feature to simplify accessing its internal VM.
bash
   minikube ssh

This command seamlessly logs you into the VM, regardless of whether you are using a virtual machine driver or Docker.

  1. Manually SSH into VM (for more granular control):
    • If you need to use SSH directly, typically for VM drivers like VirtualBox, you may need to find the specific SSH port and key:
bash
     minikube ssh-key
  • Use an SSH command with the identified key and port:
bash
     ssh -i $(minikube ssh-key) docker@$(minikube ip)
  1. Exit: After performing the necessary tasks, exit the session using:
bash
   exit

Common Issues and Troubleshooting

Even with a straightforward process, you might encounter some issues:

  • SSH Key Issues: If you can't connect, ensure the SSH key permissions are set to 600 using:
bash
  chmod 600 ~/.minikube/machines/minikube/id_rsa
  • Driver Issues: If Minikube is not starting properly, ensure the correct drivers are installed and configured.
  • Network Issues: Sometimes, firewall settings can prevent SSH access. In such cases, configure firewall rules to open the required SSH port.

Additional Information

Minikube Commands

Here is a table summarizing key Minikube commands relevant to SSH:

CommandDescription
minikube startStarts the Minikube VM or container
minikube stopStops the running Minikube instance
minikube sshSSH into Minikube's VM or container
minikube ipDisplays the IP address of the Minikube VM
minikube ssh-keyPath to the SSH private key
minikube profile listLists all Minikube profiles

Conclusion

SSHing into a Minikube environment can be straightforward yet provides deep insights and access to its underlying system for both exploration and debugging. While Minikube offers a convenient built-in SSH command, understanding how to perform the task manually provides additional flexibility, particularly in more customized or constrained environments. With these insights, developers can make the most of Minikube's capabilities and leverage its functionalities to simplify Kubernetes development workflows.

References


Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.