Kubernetes on Apple M1 using minikube

Matt Wang
3 min readJul 9, 2021

Why Kubernetes is useful

With Kubernetes, DevOps can easily scale out their applications, implement high-availability and fault-tolerant solutions.

I have quite a lot of experience in deploying scalable and high availability applications manually. Those jobs are tedious, complicated, and time-consuming, especially when there are too many nodes running applications.

Kubernetes provides a way to run and distribute applications to many nodes in one command, and it also maintains the availability of applications. Besides, with the docker image, the upgrade process for a large scale applications can be done only in few steps.

Let’s see how to setup the minikube on Apple M1.

Host environment

As macOS still does not natively support Docker, UTM is used for running an ARM64 Ubuntu VM in which Docker and minikube will be installed.

Install Docker

Minikube supports various container drivers, however, Docker is always the preferable on Linux, macOS and Windows.

Before using apt to install Docker, the setting of Docker repo goes first.

# Set up the repository 
sudo apt-get update
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release
# Add Docker's offical GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
# Here we are using the arm64 repository
echo "deb [arch=arm64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Install Docker engine
sudo apt-get install docker-ce docker-ce-cli containerd.io
# Allow current user to access docker
sudo usermod -aG docker $USER

Install minikube

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-arm64
sudo install minikube-linux-arm64 /usr/local/bin/minikube

Start & stop your cluster

minikube start # for one node cluster
minikube start --nodes 2 -p multinode-demo # for two nodes cluster

For the first time to run minikube start, minikube will create a new cluster.

Deploy your first application

In Kubernetes, deploying applications is always related to a Kubernetes object, called the Deployment. The Deployment specifies the limits of resources, Docker images, the number of replicas, settings for containers, etc.

There are two ways to create a Deployment. One is providing a Deployment specification, another is by passing argument to command line tools. CLI tools seems straightforward while the specification files look so sophisticated. But as the file can contain much more information, it is preferred in the production or complex environment. We start with CLI tools as it is easier to deal with.

The container image mentioned in minikube tutorial does work on M1(arm64). Here I am using the image from the Docker tutorial.

Create a sample deployment with two replicas and expose it on port 80:

kubectl create deployment hello-minikube --image=docker/getting-started --replicas=2
kubectl expose deployment hello-minikube --type=NodePort --port=80

hello-minikube is the name of the Deployment, and docker/getting-started is a container image in Docker Hub.

It may take few minutes to create deployment and get it ready to access. A command kubectl get deployments can be used to check the status of the Deployment.

NAME               READY   UP-TO-DATE   AVAILABLE   AGE
hello-minikube 0/2 0 0 1s

When the value of field READY becomes 2/2, hello-minikube then is available to users. Besides, there is some relevant information associated with this deployment, which includes Deployment rollout status, ReplicaSet, Pods and Service information. Those information can be retrieved by the following commands, respectively.

kubectl rollout status deployment/hello-minikube
kubectl get rs,pods,service

We particularly look at the output for Service, it is similar to this:

NAME           TYPE     CLUSTER-IP     EXTERNAL-IP   PORT(S)
hello-minikube NodePort 10.96.203.110 <none> 80:31041/TCP

“80:31041” indicates that the container is listening on 80 and the port is open for external access is 31041. The command below will show the URL for the Service:

minikube service hello-minikube
# Output: http://192.168.49.2:31041

We can use curl http://192.168.49.2:31041 to see reach the Service.

Update or Upgrade the Deployment

Kubernetes offers three ways to update the Deployment. Here we demonstrate the way via editing the Deployment specification file:

kubectl edit deployment.v1.apps/hello-minikube

This command will start an editor with the specification file opened. In this case, the update we need to do is to change the container image version from docker/getting-started to docker/getting-started:latest. It may look like this:

New container image: docker/getting-started:latest

We save the file and exit the editor. Kubernetes will check the changes and apply to the Deployment.

References

[1] https://kubernetes.io/docs/concepts/workloads/controllers/deployment

--

--

Matt Wang

Empowering others through handy and innovative tech solutions and sharing knowledge. Stay tuned with my new articles.