|
| 1 | +--- |
| 2 | +title: Hello Minikube |
| 3 | +content_template: templates/tutorial |
| 4 | +weight: 5 |
| 5 | +menu: |
| 6 | + main: |
| 7 | + title: "Cominciamo!" |
| 8 | + weight: 10 |
| 9 | + post: > |
| 10 | + <p>Sei pronto a cominciare con Kubernetes? Crea un Kubernetes cluster ed esegui un'appliczione di esempio.</p> |
| 11 | +card: |
| 12 | + name: tutorials |
| 13 | + weight: 10 |
| 14 | +--- |
| 15 | + |
| 16 | +{{% capture overview %}} |
| 17 | + |
| 18 | +Questo tutorial mostra come eseguire una semplice applicazione in Kubernetes |
| 19 | +utilizzando [Minikube](/docs/setup/learning-environment/minikube) e Katacoda. |
| 20 | +Katacoda permette di operare su un'installazione di Kubernetes dal tuo browser. |
| 21 | + |
| 22 | +{{< note >}} |
| 23 | +Come alternativa, è possibile eseguire questo tutorial [installando minikube](/docs/tasks/tools/install-minikube/) localmente. |
| 24 | +{{< /note >}} |
| 25 | + |
| 26 | +{{% /capture %}} |
| 27 | + |
| 28 | +{{% capture objectives %}} |
| 29 | + |
| 30 | +* Rilasciare una semplice applicazione su Minikube. |
| 31 | +* Eseguire l'applicazione. |
| 32 | +* Visualizzare i log dell'applicazione. |
| 33 | + |
| 34 | +{{% /capture %}} |
| 35 | + |
| 36 | +{{% capture prerequisites %}} |
| 37 | + |
| 38 | +Questo tutorial fornisce una container image che utilizza NGINX per risponde a tutte le richieste |
| 39 | +con un echo che visualizza i dati della richiesta stessa. |
| 40 | + |
| 41 | +{{% /capture %}} |
| 42 | + |
| 43 | +{{% capture lessoncontent %}} |
| 44 | + |
| 45 | +## Crea un Minikube cluster |
| 46 | + |
| 47 | +1. Click **Launch Terminal** |
| 48 | + |
| 49 | + {{< kat-button >}} |
| 50 | + |
| 51 | + {{< note >}}Se hai installato Minikube localmente, esegui `minikube start`.{{< /note >}} |
| 52 | + |
| 53 | +2. Apri la console di Kubernetes nel browser: |
| 54 | + |
| 55 | + ```shell |
| 56 | + minikube dashboard |
| 57 | + ``` |
| 58 | + |
| 59 | +3. Katacoda environment only: In alto alla finestra del terminale, fai click segno più, e a seguire click su **Select port to view on Host 1**. |
| 60 | + |
| 61 | +4. Katacoda environment only: Inserisci `30000`, a seguire click su **Display Port**. |
| 62 | + |
| 63 | +## Crea un Deployment |
| 64 | + |
| 65 | +Un Kubernetes [*Pod*](/docs/concepts/workloads/pods/pod/) è un gruppo di uno o più Containers, |
| 66 | +che sono uniti tra loro dal punto di vista amministrativo e che condividono lo stesso network. |
| 67 | +Il Pod in questo tutorial ha un solo Container. Un Kubernetes |
| 68 | +[*Deployment*](/docs/concepts/workloads/controllers/deployment/) monitora lo stato del Pod ed |
| 69 | +eventualmente provvedere a farlo ripartire nel caso questo termini. L'uso dei Deployments è la |
| 70 | +modalità raccomandata per gestire la creazione e lo scaling dei Pods. |
| 71 | +
|
| 72 | +
|
| 73 | +1. Usa il comando `kubectl create` per creare un Deployment che gestisce un singolo Pod. Il Pod |
| 74 | +eseguirà un Container basato sulla Docker image specificata. |
| 75 | +
|
| 76 | + ```shell |
| 77 | + kubectl create deployment hello-node --image=k8s.gcr.io/echoserver:1.4 |
| 78 | + ``` |
| 79 | +
|
| 80 | +2. Visualizza il Deployment: |
| 81 | +
|
| 82 | + ```shell |
| 83 | + kubectl get deployments |
| 84 | + ``` |
| 85 | +
|
| 86 | + L'output del comando è simile a: |
| 87 | + |
| 88 | + ``` |
| 89 | + NAME READY UP-TO-DATE AVAILABLE AGE |
| 90 | + hello-node 1/1 1 1 1m |
| 91 | + ``` |
| 92 | + |
| 93 | +3. Visualizza il Pod creato dal Deployment: |
| 94 | + |
| 95 | + ```shell |
| 96 | + kubectl get pods |
| 97 | + ``` |
| 98 | + |
| 99 | + L'output del comando è simile a: |
| 100 | +
|
| 101 | + ``` |
| 102 | + NAME READY STATUS RESTARTS AGE |
| 103 | + hello-node-5f76cf6ccf-br9b5 1/1 Running 0 1m |
| 104 | + ``` |
| 105 | +
|
| 106 | +4. Visualizza gli eventi del cluster Kubernetes: |
| 107 | +
|
| 108 | + ```shell |
| 109 | + kubectl get events |
| 110 | + ``` |
| 111 | +
|
| 112 | +5. Visualizza la configurazione di `kubectl`: |
| 113 | +
|
| 114 | + ```shell |
| 115 | + kubectl config view |
| 116 | + ``` |
| 117 | +
|
| 118 | +{{< note >}}Per maggiori informazioni sui comandi di `kubectl`, vedi [kubectl overview](/docs/user-guide/kubectl-overview/).{{< /note >}} |
| 119 | +
|
| 120 | +## Crea un Service |
| 121 | +
|
| 122 | +Con le impostazioni di default, un Pod è accessibile solamente dagli indirizzi IP interni |
| 123 | +al Kubernetes cluster. Per far si che il Container `hello-node` sia accessibile dall'esterno |
| 124 | +del Kubernetes virtual network, è necessario esporre il Pod utilizzando un |
| 125 | +Kubernetes [*Service*](/docs/concepts/services-networking/service/). |
| 126 | + |
| 127 | +1. Esponi il Pod su internet untilizzando il comando `kubectl expose`: |
| 128 | + |
| 129 | + ```shell |
| 130 | + kubectl expose deployment hello-node --type=LoadBalancer --port=8080 |
| 131 | + ``` |
| 132 | + |
| 133 | + Il flag `--type=LoadBalancer` indica la volontà di esporre il Service |
| 134 | + all'esterno del Kubernetes cluster. |
| 135 | +
|
| 136 | +2. Visualizza il Servizio appena creato: |
| 137 | +
|
| 138 | + ```shell |
| 139 | + kubectl get services |
| 140 | + ``` |
| 141 | +
|
| 142 | + L'output del comando è simile a: |
| 143 | + |
| 144 | + ``` |
| 145 | + NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE |
| 146 | + hello-node LoadBalancer 10.108.144.78 <pending> 8080:30369/TCP 21s |
| 147 | + kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 23m |
| 148 | + ``` |
| 149 | + |
| 150 | + Nei cloud providers che supportano i servizi di tipo load balancers, |
| 151 | + viene fornito un indirizzo IP pubblico per permettere l'acesso al Service. Su Minikube, |
| 152 | + il service type `LoadBalancer` rende il Service accessibile attraverso il comando `minikube service`. |
| 153 | +
|
| 154 | +3. Esegui il comando: |
| 155 | +
|
| 156 | + ```shell |
| 157 | + minikube service hello-node |
| 158 | + ``` |
| 159 | +
|
| 160 | +4. Katacoda environment only: Fai click segno più, e a seguire click su **Select port to view on Host 1**. |
| 161 | +
|
| 162 | +5. Katacoda environment only: Fai attenzione al numero di 5 cifre visualizzato a fianco di `8080` nell'output del comando. Questo port number è generato casualmente e può essere diverso nel tuo caso. Inserisci il tuo port number nella textbox, e a seguire fai click su Display Port. Nell'esempio precedente, avresti scritto `30369`. |
| 163 | +
|
| 164 | + Questo apre un finestra nel browser dove l'applicazione visuallizza l'echo delle richieste ricevute. |
| 165 | +
|
| 166 | +## Attiva gli addons |
| 167 | +
|
| 168 | +Minikube include un set {{< glossary_tooltip text="addons" term_id="addons" >}} che possono essere attivati, disattivati o eseguti nel ambiente Kubernetes locale. |
| 169 | +
|
| 170 | +1. Elenca gli addons disponibili: |
| 171 | +
|
| 172 | + ```shell |
| 173 | + minikube addons list |
| 174 | + ``` |
| 175 | +
|
| 176 | + L'output del comando è simile a: |
| 177 | + |
| 178 | + ``` |
| 179 | + addon-manager: enabled |
| 180 | + dashboard: enabled |
| 181 | + default-storageclass: enabled |
| 182 | + efk: disabled |
| 183 | + freshpod: disabled |
| 184 | + gvisor: disabled |
| 185 | + helm-tiller: disabled |
| 186 | + ingress: disabled |
| 187 | + ingress-dns: disabled |
| 188 | + logviewer: disabled |
| 189 | + metrics-server: disabled |
| 190 | + nvidia-driver-installer: disabled |
| 191 | + nvidia-gpu-device-plugin: disabled |
| 192 | + registry: disabled |
| 193 | + registry-creds: disabled |
| 194 | + storage-provisioner: enabled |
| 195 | + storage-provisioner-gluster: disabled |
| 196 | + ``` |
| 197 | + |
| 198 | +2. Attiva un addon, per esempio, `metrics-server`: |
| 199 | + |
| 200 | + ```shell |
| 201 | + minikube addons enable metrics-server |
| 202 | + ``` |
| 203 | + |
| 204 | + L'output del comando è simile a: |
| 205 | +
|
| 206 | + ``` |
| 207 | + metrics-server was successfully enabled |
| 208 | + ``` |
| 209 | +
|
| 210 | +3. Visualizza i Pods ed i Service creati in precedenza: |
| 211 | +
|
| 212 | + ```shell |
| 213 | + kubectl get pod,svc -n kube-system |
| 214 | + ``` |
| 215 | +
|
| 216 | + L'output del comando è simile a: |
| 217 | + |
| 218 | + ``` |
| 219 | + NAME READY STATUS RESTARTS AGE |
| 220 | + pod/coredns-5644d7b6d9-mh9ll 1/1 Running 0 34m |
| 221 | + pod/coredns-5644d7b6d9-pqd2t 1/1 Running 0 34m |
| 222 | + pod/metrics-server-67fb648c5 1/1 Running 0 26s |
| 223 | + pod/etcd-minikube 1/1 Running 0 34m |
| 224 | + pod/influxdb-grafana-b29w8 2/2 Running 0 26s |
| 225 | + pod/kube-addon-manager-minikube 1/1 Running 0 34m |
| 226 | + pod/kube-apiserver-minikube 1/1 Running 0 34m |
| 227 | + pod/kube-controller-manager-minikube 1/1 Running 0 34m |
| 228 | + pod/kube-proxy-rnlps 1/1 Running 0 34m |
| 229 | + pod/kube-scheduler-minikube 1/1 Running 0 34m |
| 230 | + pod/storage-provisioner 1/1 Running 0 34m |
| 231 | + |
| 232 | + NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE |
| 233 | + service/metrics-server ClusterIP 10.96.241.45 <none> 80/TCP 26s |
| 234 | + service/kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP 34m |
| 235 | + service/monitoring-grafana NodePort 10.99.24.54 <none> 80:30002/TCP 26s |
| 236 | + service/monitoring-influxdb ClusterIP 10.111.169.94 <none> 8083/TCP,8086/TCP 26s |
| 237 | + ``` |
| 238 | + |
| 239 | +4. Disabilita `metrics-server`: |
| 240 | + |
| 241 | + ```shell |
| 242 | + minikube addons disable metrics-server |
| 243 | + ``` |
| 244 | + |
| 245 | + L'output del comando è simile a: |
| 246 | +
|
| 247 | + ``` |
| 248 | + metrics-server was successfully disabled |
| 249 | + ``` |
| 250 | +
|
| 251 | +## Clean up |
| 252 | +
|
| 253 | +Adesso puoi procedere a fare clean up delle risorse che hai creato nel tuo cluster: |
| 254 | +
|
| 255 | +```shell |
| 256 | +kubectl delete service hello-node |
| 257 | +kubectl delete deployment hello-node |
| 258 | +``` |
| 259 | +
|
| 260 | +Eventualmente, puoi stoppare la Minikube virtual machine (VM): |
| 261 | +
|
| 262 | +```shell |
| 263 | +minikube stop |
| 264 | +``` |
| 265 | +
|
| 266 | +Eventualmente, puoi cancellare la Minikube VM: |
| 267 | +
|
| 268 | +```shell |
| 269 | +minikube delete |
| 270 | +``` |
| 271 | +
|
| 272 | +{{% /capture %}} |
| 273 | +
|
| 274 | +{{% capture whatsnext %}} |
| 275 | +
|
| 276 | +* Approfondisci la tua conoscenza dei [Deployments](/docs/concepts/workloads/controllers/deployment/). |
| 277 | +* Approfondisci la tua conoscenza di [Rilasciare applicazioni](/docs/tasks/run-application/run-stateless-application-deployment/). |
| 278 | +* Approfondisci la tua conoscenza dei [Services](/docs/concepts/services-networking/service/). |
| 279 | +
|
| 280 | +{{% /capture %}} |
0 commit comments