When learning a new technology project, one of the most troublesome aspects is how to quickly install the relevant environment so that your teammates can get started quickly. Learning Kubernetes is no exception. To build a Kubernetes development environment in a local environment, you need to install Docker, Kubernetes, Minikube, Kubectl and other related tools, all of which are tedious to install and configure, and prone to errors. Is there a quick way to bypass these and quickly build a Kubernetes development environment on your own computer? Apart from Minikube, you may have heard of k3s, kind and other tools, but they can be quite difficult for newcomers. Today we’re introducing a new tool, Colima, which allows you to run lightweight virtual machines in your local environment and run Kubernetes clusters in your virtual machines.

What is Colima

Colima is a lightweight virtualisation tool based on Docker that allows you to run lightweight virtual machines in a local environment. You can use Colima to build and run Kubernetes clusters in your local environment.

Colima provides a command line interface to manage VMs and containers with simple commands. It allows you to run one or more lightweight VMs locally and run Kubernetes clusters within the VMs.

Setting up a Kubernetes environment with Colima is relatively straightforward, as it automatically handles the installation and configuration of your VMs and Kubernetes. All you need to do is run the appropriate commands and Colima will deploy Kubernetes in the VM and provide you with Kubernetes management commands and a user interface.

Colima provides a fast and lightweight way to run Kubernetes on local machines and is particularly suited to development and testing needs. Please note that Colima is currently in the developer preview phase and may not yet be available for production environments. If you intend to run Kubernetes in a production environment, it is recommended that you consider using a formally supported tool or hosted service, such as a service provider that hosts a Kubernetes cluster, such as Google Kubernetes Engine (GKE), Amazon Elastic Kubernetes Service (EKS), and Microsoft Azure Kubernetes Service (AKS).

The goal of the Colima project is to install a Container Runtime environment on MacOS with minimal effort. The name Colima is also known as Container in Lima.

Install Colima

Colima can be run on Linux, macOS. You can find the installation guide for Colima on GitHub.

1
2
3
4
# Stable Version
brew install colima
# Development Version
brew install --HEAD colima

In addition to installing colima, you need to install brew install docker in order to use docker runtime.

Using Colima

Colima provides a command line interface to manage VMs and containers with simple commands. It allows you to run one or more lightweight VMs locally and to run Kubernetes clusters within your VMs.

Starting Colima

You can start Colima with the colima start command, which will automatically download and install a Docker image of Colima if you run it for the first time. If you already have Colima installed, it will start Colima.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# Starting Colima
colima start
# Edit the configuration file and restart
colima start --edit
# Use containerd as runtime
colima start --runtime containerd
# Starting Kubernetes
colima start --kubernetes
# Starting Kubernetes and using containerd as runtime
colima start --runtime containerd --kubernetes
# Specify CPU, memory, disk size
colima start --cpu 4 --memory 8 --disk 100
# Specify DNS
colima start --dns 1.1.1.1 --dns 8.8.8.8

The default profile is default. If you want to start more profiles, you can specify them with the --profile parameter.

1
2
# Start Colima
colima start --profile myprofile

Editing the Colima settings file

You can use the colima edit command to edit Colima’s profile. If you run this command for the first time, it will automatically create a new profile. If you already have a profile, it will open the existing profile.

1
vi $HOME/.colima/default/colima.yaml

Note that runtime is preset to docker and if you want to use containerd, you need to change the value of runtime.

1
2
3
# Container runtime to be used (docker, containerd).
# Default: docker
runtime: docker

Or to add an in-house Private Registry, you can set it up via docker.

1
2
3
4
5
# EXAMPLE - add insecure registries
docker:
  insecure-registries:
    - myregistry.com:5000
    - host.docker.internal:5000

Stop/delete Colima

To stop Colima, you can use the colima stop command. To delete Colima, you can use the colima delete command.

1
2
3
4
# Stop Colima
colima stop
# Delete Colima
colima delete

The default Profile is default and can be specified by the -profile parameter if you want to delete a specific Profile.

1
2
# Delete Colima
colima delete --profile myprofile

Checking Colima status

You can use the colima status command to check the status of Colima.

1
2
# Status Colima
colima status <profile>

where profile can be omitted and the default is default.

Starting a Kubernetes environment

The above tutorial allows you to quickly start a Kubernetes environment using the following commands.

1
2
# Start Colima
colima start --kubernetes <profile>
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
$ colima start --runtime docker --kubernetes foobar
INFO[0000] starting colima [profile=foobar]
INFO[0000] runtime: docker+k3s
INFO[0000] preparing network ...                         context=vm
INFO[0000] creating and starting ...                     context=vm
INFO[0108] provisioning ...                              context=docker
INFO[0108] starting ...                                  context=docker
INFO[0113] provisioning ...                              context=kubernetes
INFO[0114] downloading and installing ...                context=kubernetes
INFO[0379] loading oci images ...                        context=kubernetes
INFO[0385] starting ...                                  context=kubernetes
INFO[0389] updating config ...                           context=kubernetes
INFO[0390] Switched to context "colima-foobar".          context=kubernetes
INFO[0390] done

The Kubernetes environment can be viewed via the kubeconfig file.

1
2
3
CURRENT   NAME                                   CLUSTER                                AUTHINFO                               NAMESPACE
          colima                                 colima                                 colima
*         colima-foobar                          colima-foobar                          colima-foobar

You can see that if it is a default profile name it is colima and if it is a foobar profile name it is colima-foobar. We can switch between profiles with kubectl config use-context and we’ll start by creating a Deployment.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 2
      maxUnavailable: 1
  minReadySeconds: 5
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx:latest
        name: nginx
        ports:
        - containerPort: 80
        resources:
          requests:
            memory: "64Mi"
            cpu: "250m"
          limits:
            memory: "128Mi"
            cpu: "500m"

---
apiVersion: v1
kind: Service
metadata:
  name: nginx-nodeport
spec:
  type: NodePort
  selector:
    app: nginx
  ports:
  - name: http
    protocol: TCP
    port: 8080
    targetPort: 80

Use the kubectl apply command to create a Deployment.

1
kubectl apply -f nginx.yaml

Check status.

1
2
3
$ kubectl get deployments.apps
NAME    READY   UP-TO-DATE   AVAILABLE   AGE
nginx   2/2     2            2           104s

You can create your own service environment to suit your needs.

Summary

Colima provides a fast and lightweight way to run Kubernetes on a local machine and is particularly suited to development and testing needs. If you want to build a Kubernetes development environment in your local environment, try Colima, which allows you to run lightweight virtual machines in your local environment and run Kubernetes clusters in your virtual machines. Developers can just concentrate on writing Yaml. Sometimes team members want to try out Kubernetes but don’t want to spend too much time installing and configuring Kubernetes, so Colima is a good choice. Of course, you can also choose Docker Desktop or Minikube or Rancher Desktop, but The advantage of Colima is that it is lightweight, and the installation and configuration process is relatively simple.

Ref

  • https://blog.wu-boy.com/2023/06/how-to-create-kubernetes-cluster-in-local/