Minikube è uno strumento open source che ti aiuta a configurare un cluster Kubernetes a nodo singolo sul tuo computer locale. Semplifica l'esecuzione di un cluster Kubernetes a nodo singolo sul tuo personal computer per il lavoro di sviluppo quotidiano. È multipiattaforma e può essere installato su macOS, Linux e Windows.
In questo tutorial, ti mostreremo come installare Minikube sul server Ubuntu 20.04.
Prerequisiti
- Desktop Ubuntu 20.04 installato nel tuo sistema.
- Minimo 4 GB di RAM e 2 o più core della CPU.
- La virtualizzazione dell'hardware deve essere abilitata nel tuo sistema locale.
- Una password di root è configurata sul server.
Per iniziare
Prima di iniziare, si consiglia di aggiornare i pacchetti di sistema all'ultima versione. Puoi aggiornarli eseguendo il seguente comando:
apt-get update -y
Una volta aggiornati tutti i pacchetti, installa altre dipendenze eseguendo il comando seguente:
apt-get install curl wget apt-transport-https virtualbox virtualbox-ext-pack -y
Una volta terminato, puoi procedere al passaggio successivo.
Installa Docker
Successivamente, dovrai installare Docker sul tuo sistema. Puoi installarlo eseguendo il seguente comando:
apt-get install docker.io -y
Una volta installato Docker, avvia il servizio Docker e abilitalo all'avvio al riavvio del sistema:
systemctl start docker
systemctl enable docker
Ora puoi verificare la versione Docker utilizzando il seguente comando:
docker --version
Dovresti vedere la versione Docker nel seguente output:
Docker version 19.03.8, build afacb8b7f0
Una volta terminato, puoi procedere al passaggio successivo.
Installa Minikube
Per impostazione predefinita, Minikube non è disponibile nel repository predefinito di Ubuntu. Quindi dovrai scaricare il pacchetto binario Minikube dal suo sito Web ufficiale. Puoi scaricarlo con il seguente comando:
wget https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
Una volta completato il download, copia il binario scaricato nel percorso di sistema utilizzando il seguente comando:
cp minikube-linux-amd64 /usr/local/bin/minikube
Quindi, fornisci il permesso di esecuzione con il seguente comando:
chmod 755 /usr/local/bin/minikube
Ora puoi verificare la versione di Minikube con il seguente comando:
minikube version
Dovresti ottenere il seguente output:
minikube version: v1.16.0 commit: 9f1e482427589ff8451c4723b6ba53bb9742fbb1
Una volta terminato, puoi procedere al passaggio successivo.
Installa Kubectl
Successivamente, dovrai installare Kubectl e altri strumenti per gestire le applicazioni su Kubernetes. Innanzitutto, aggiungi la chiave GPG con il seguente comando:
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
Quindi, aggiungi il repository kubectl con il seguente comando:
echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" | tee /etc/apt/sources.list.d/kubernetes.list
Una volta aggiunto il repository, aggiorna la cache del repository e installa Kubectl eseguendo il comando seguente:
apt-get update -y
apt-get install kubectl kubeadm kubectl -y
Una volta installati tutti i pacchetti, puoi procedere al passaggio successivo.
Avvia Minikube
A questo punto, tutti i pacchetti richiesti sono installati. Ora puoi avviare Minikube con il seguente comando:
minikube start
Dovresti ottenere il seguente output:
* minikube v1.16.0 on Ubuntu 20.04 (kvm/amd64) * Using the none driver based on user configuration * Starting control plane node minikube in cluster minikube * Running on localhost (CPUs=2, Memory=3936MB, Disk=100726MB) ... * OS release is Ubuntu 20.04 LTS * Preparing Kubernetes v1.20.0 on Docker 19.03.8 ... - kubelet.resolv-conf=/run/systemd/resolve/resolv.conf > kubectl.sha256: 64 B / 64 B [--------------------------] 100.00% ? p/s 0s > kubeadm.sha256: 64 B / 64 B [--------------------------] 100.00% ? p/s 0s > kubelet.sha256: 64 B / 64 B [--------------------------] 100.00% ? p/s 0s > kubeadm: 37.40 MiB / 37.40 MiB [---------------] 100.00% 27.29 MiB p/s 1s > kubectl: 38.37 MiB / 38.37 MiB [---------------] 100.00% 27.60 MiB p/s 1s > kubelet: 108.69 MiB / 108.69 MiB [-------------] 100.00% 42.08 MiB p/s 3s - Generating certificates and keys ... - Booting up control plane ... - Configuring RBAC rules ... * Configuring local host environment ... * ! The 'none' driver is designed for experts who need to integrate with an existing VM * Most users should use the newer 'docker' driver instead, which does not require root! * For more information, see: https://minikube.sigs.k8s.io/docs/reference/drivers/none/ * ! kubectl and minikube configuration will be stored in /root ! To use kubectl or minikube commands as your own user, you may need to relocate them. For example, to overwrite your own settings, run: * - sudo mv /root/.kube /root/.minikube $HOME - sudo chown -R $USER $HOME/.kube $HOME/.minikube * * This can also be done automatically by setting the env var CHANGE_MINIKUBE_NONE_USER=true * Verifying Kubernetes components... * Enabled addons: storage-provisioner, default-storageclass * Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default
Puoi controllare le informazioni sul cluster con il seguente comando:
kubectl cluster-info
Dovresti ottenere il seguente output:
Kubernetes control plane is running at https://45.58.38.77:8443 KubeDNS is running at https://45.58.38.77:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
Puoi controllare la configurazione predefinita di Kubectl con il seguente comando:
kubectl config view
Dovresti vedere il seguente output:
apiVersion: v1 clusters: - cluster: certificate-authority: /root/.minikube/ca.crt server: https://45.58.38.77:8443 name: minikube contexts: - context: cluster: minikube namespace: default user: minikube name: minikube current-context: minikube kind: Config preferences: {} users: - name: minikube user: client-certificate: /root/.minikube/profiles/minikube/client.crt client-key: /root/.minikube/profiles/minikube/client.key
Puoi controllare tutti i nodi in esecuzione con il seguente comando:
kubectl get nodes
Dovresti ottenere il seguente output:
NAME STATUS ROLES AGE VERSION ubuntu2004 Ready control-plane,master 2m24s v1.20.0
Per verificare lo stato di Minikube, esegui il seguente comando:
minikube status
Dovresti ottenere il seguente output:
minikube type: Control Plane host: Running kubelet: Running apiserver: Running kubeconfig: Configured timeToStop: Nonexistent
Una volta terminato, puoi procedere al passaggio successivo.
Accedi al dashboard di Kubernetes
Minikube viene fornito con molti componenti aggiuntivi che puoi abilitare o disabilitare secondo le tue esigenze. Puoi elencare tutti i componenti aggiuntivi con il seguente comando:
minikube addons list
Dovresti ottenere il seguente output:
|-----------------------------|----------|--------------| | ADDON NAME | PROFILE | STATUS | |-----------------------------|----------|--------------| | ambassador | minikube | disabled | | csi-hostpath-driver | minikube | disabled | | dashboard | minikube | disabled | | default-storageclass | minikube | enabled ? | | efk | minikube | disabled | | freshpod | minikube | disabled | | gcp-auth | minikube | disabled | | gvisor | minikube | disabled | | helm-tiller | minikube | disabled | | ingress | minikube | disabled | | ingress-dns | minikube | disabled | | istio | minikube | disabled | | istio-provisioner | minikube | disabled | | kubevirt | minikube | disabled | | logviewer | minikube | disabled | | metallb | minikube | disabled | | metrics-server | minikube | disabled | | nvidia-driver-installer | minikube | disabled | | nvidia-gpu-device-plugin | minikube | disabled | | olm | minikube | disabled | | pod-security-policy | minikube | disabled | | registry | minikube | disabled | | registry-aliases | minikube | disabled | | registry-creds | minikube | disabled | | storage-provisioner | minikube | enabled ? | | storage-provisioner-gluster | minikube | disabled | | volumesnapshots | minikube | disabled | |-----------------------------|----------|--------------|
Quindi, elenca tutte le immagini del contenitore in esecuzione nel cluster con il comando seguente:
kubectl get pods --all-namespaces
Dovresti ottenere il seguente output:
NAMESPACE NAME READY STATUS RESTARTS AGE kube-system coredns-74ff55c5b-skf9d 1/1 Running 0 3m45s kube-system etcd-ubuntu2004 1/1 Running 0 3m54s kube-system kube-apiserver-ubuntu2004 1/1 Running 0 3m54s kube-system kube-controller-manager-ubuntu2004 1/1 Running 0 3m54s kube-system kube-proxy-w8q6d 1/1 Running 0 3m45s kube-system kube-scheduler-ubuntu2004 1/1 Running 0 3m54s kube-system storage-provisioner 1/1 Running 0 3m59s
Quindi, abilita la dashboard Kubernetes e ottieni l'URL della dashboard con il comando seguente:
minikube dashboard --url
Dovresti ottenere il seguente output:
* Enabling dashboard ... * Verifying dashboard health ... * Launching proxy ... * Verifying proxy health ... http://127.0.0.1:36499/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/ You can now access and manage the Kubernetes cluster using the URL http://127.0.0.1:36499/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/
Conclusione
Nella guida sopra, hai imparato come installare Minikube e usarlo per configurare un cluster Kubernetes su Ubuntu 20.04. Ora puoi utilizzare Minikube per configurare il cluster Kubernetes in locale e gestirlo dal browser web. Sentiti libero di chiedermi se hai domande.