minikube

Minikube installation on Windows wsl Ubuntu

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

Start your cluster

minikube start --mount=true --mount-string="/minikube-volume-abs:/minikube-volume-mount"

A more complete command to start a cluster with multiple options

start-minikube.sh

#!/bin/bash
minikube start --static-ip 192.168.49.2 --nodes 1 --insecure-registry registry.mydavidh.org:5000 --mount=true --mount-string="/minikube-volume-abs:/minikube-volume-mount" --ports="30000:30000,30001:30001,8080:8080,8081:8081"
kubectl config set-context --current --namespace=my-apps
 
export DEV_IP=172.16.1.1
sudo ifconfig lo:0 $DEV_IP
minikube ssh "echo \"$DEV_IP       registry.mydavidh.org\" | sudo tee -a  /etc/hosts"

Helpful information:

– We use a static IP to be able to use with a constant address a reference from the pod to the minikube host. This is helpful for communication between pods relying on cluster IP.

– We specify one node but we can specify more.

– We specify to use an insecure registry. Of course, this registry has to be defined separately.

– We use a mount

– We specify a port forwarding from the pod to the (external) host.

After the mini cube start we do some other tasks:
– We set the kubernetes context
– We define a fixed IP for the registry inside minikube host

The mount option in minikube

Only the start argument is required to start a cluster. But if we want to mount some volumes as host path in our kubernetes deployment objects, we need to specify a mount.
Documentation:
--mount-string='/minikube-volume-abs:/minikube-volume-mount':
The argument to pass the minikube mount command on start.
The first part of the argument /minikube-volume-abs specifies the physical location of the directory on the host.
The second part of the argument minikube-volume-mount specifies the virtual location of the directory that we could specify on the kubernetes deployment object.
Example:

david@david-PC / $
ls -lah
total 2.0M
drwxr-xr-x  21 root root 4.0K May 17 13:47 .
drwxr-xr-x  21 root root 4.0K May 17 13:47 ..
lrwxrwxrwx   1 root root    7 Feb 16  2022 bin -> usr/bin
drwxr-xr-x   2 root root 4.0K Feb 16  2022 boot
drwxr-xr-x 101 root root 4.0K May 17 15:46 etc
drwxr-xr-x   3 root root 4.0K May  1 14:34 home
.....................
drwxr-xr-x   4 root root 4.0K May 17 15:22 minikube-volume-abs
      volumes:
        - name: prometheus-config
          hostPath:
            path: /minikube-volume-mount/prometheus-config
        - name: prometheus-data
          hostPath:
            path: /minikube-volume-mount/prometheus-data

Helpful information

Access to the host from a pod: host.minikube.internal

Start minikube to be able to use a local docker registry

Reference:
https://gist.github.com/trisberg/37c97b6cc53def9a3e38be6143786589
Here we also set a mount:
minikube start --insecure-registry registry.mydavidh.org:5000 --mount=true --mount-string="/minikube-volume-abs:/minikube-volume-mount"
A last step is required to make minikube to be able to query the registry: adding the host mapping.

export DEV_IP=172.16.1.1
sudo ifconfig lo:0 $DEV_IP
minikube ssh "echo \"$DEV_IP       registry.mydavidh.org\" | sudo tee -a  /etc/hosts"

How to use kubectl with minikube

– If you have kubectl installed, you can use it.
– Else minikube can download the appropriate version of kubectl if you run the subcommand kubectl:
minikube kubectl -- get pod
Enable completion :
alias kubectl="minikube kubectl --"

Other common Minikube commands

Stops a local Kubernetes cluster.
It stops the underlying VM or container, but keeps user data intact.
The cluster can be started again with the start command.
minikube stop

Pause Kubernetes.
It does not impact deployed applications.
minikube pause

Unpause a paused instance.
minikube unpause

Deletes a local Kubernetes cluster.
It deletes the underlying VM or container and removes all associated files. minikube delete

Returns the Kubernetes URL(s) for service(s) in your local cluster.
minikube service -n
The -n parameter represents the service namespace.
By default, minikube uses the « default » namespace.

Example:

kubectl get -A service
NAMESPACE     NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                  AGE
default       kubernetes   ClusterIP   10.96.0.1        <none>        443/TCP                  21h
kube-system   kube-dns     ClusterIP   10.96.0.10       <none>        53/UDP,53/TCP,9153/TCP   21h
tools         prometheus   NodePort    10.107.175.208   <none>        9090:31000/TCP           21h
david@david-PC / $
minikube service -n tools prometheus
|-----------|------------|--------------|---------------------------|
| NAMESPACE |    NAME    | TARGET PORT  |            URL            |
|-----------|------------|--------------|---------------------------|
| tools     | prometheus | prom-ui/9090 | http://192.168.49.2:31000 |
|-----------|------------|--------------|---------------------------|
&#x1f3c3;  Starting tunnel for service prometheus.
|-----------|------------|-------------|------------------------|
| NAMESPACE |    NAME    | TARGET PORT |          URL           |
|-----------|------------|-------------|------------------------|
| tools     | prometheus |             | http://127.0.0.1:36483 |
|-----------|------------|-------------|------------------------|
&#x1f389;  Opening service tools/prometheus in default browser...
&#x1f449;  http://127.0.0.1:36483
❗  Because you are using a Docker driver on linux, the terminal needs to be open to run it.

Provides instructions to point your terminal’s docker-cli to the Docker Engine inside minikube.
minikube docker-env
This command is useful to know how the docker containers are running and to run containers inside minikube context.

Example output:

    minikube docker-env
    export DOCKER_TLS_VERIFY="1"
    export DOCKER_HOST="tcp://127.0.0.1:49186"
    export DOCKER_CERT_PATH="/home/david/.minikube/certs"
    export MINIKUBE_ACTIVE_DOCKERD="minikube"

To point your shell to minikube’s docker-daemon:
eval $(minikube -p minikube docker-env)

Export a docker image from the docker host to the minikube host

docker save registry.mydavidh.org:5000/modeler-flask:1.0.0  -o modeler-flask.tar
eval $(minikube docker-env)
docker load -i modeler-flask.tar

Common options

-p, --profile profile_foo : the name of the minikube VM being used.
This can be set to allow having multiple instances of minikube independently. (default « minikube »)

Ce contenu a été publié dans Non classé. Vous pouvez le mettre en favoris avec ce permalien.

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *