2017-01-07 03:36:16 +00:00
|
|
|
---
|
|
|
|
title: Hello Minikube
|
2018-05-05 16:00:51 +00:00
|
|
|
content_template: templates/tutorial
|
2018-05-15 22:29:27 +00:00
|
|
|
weight: 5
|
2018-09-14 21:47:24 +00:00
|
|
|
menu:
|
|
|
|
main:
|
|
|
|
title: "Get Started"
|
|
|
|
weight: 10
|
|
|
|
post: >
|
|
|
|
<p>Ready to get your hands dirty? Build a simple Kubernetes cluster that runs "Hello World" for Node.js.</p>
|
2017-01-07 03:36:16 +00:00
|
|
|
---
|
|
|
|
|
2018-05-05 16:00:51 +00:00
|
|
|
{{% capture overview %}}
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2018-11-05 19:31:11 +00:00
|
|
|
This tutorial shows you how to run a simple Hello World Node.js app
|
|
|
|
on Kubernetes using [Minikube](/docs/getting-started-guides/minikube) and Katacoda.
|
|
|
|
Katacoda provides a free, in-browser Kubernetes environment.
|
|
|
|
|
|
|
|
{{< note >}}
|
2018-11-16 18:22:21 +00:00
|
|
|
You can also follow this tutorial if you've installed [Minikube locally](/docs/tasks/tools/install-minikube/).
|
2018-11-05 19:31:11 +00:00
|
|
|
{{< /note >}}
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2018-05-05 16:00:51 +00:00
|
|
|
{{% /capture %}}
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2018-05-05 16:00:51 +00:00
|
|
|
{{% capture objectives %}}
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2018-11-05 19:31:11 +00:00
|
|
|
* Deploy a hello world application to Minikube.
|
|
|
|
* Run the app.
|
2016-12-13 06:36:19 +00:00
|
|
|
* View application logs.
|
|
|
|
|
2018-05-05 16:00:51 +00:00
|
|
|
{{% /capture %}}
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2018-05-05 16:00:51 +00:00
|
|
|
{{% capture prerequisites %}}
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2018-11-05 19:31:11 +00:00
|
|
|
This tutorial provides a container image built from the following files:
|
2018-05-06 18:43:50 +00:00
|
|
|
|
2018-11-05 19:31:11 +00:00
|
|
|
{{< codenew language="js" file="minikube/server.js" >}}
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2018-11-05 19:31:11 +00:00
|
|
|
{{< codenew language="conf" file="minikube/Dockerfile" >}}
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2018-11-16 18:22:21 +00:00
|
|
|
For more information on the `docker build` command, read the [Docker documentation](https://docs.docker.com/engine/reference/commandline/build/).
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2018-05-05 16:00:51 +00:00
|
|
|
{{% /capture %}}
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2018-05-05 16:00:51 +00:00
|
|
|
{{% capture lessoncontent %}}
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2017-01-18 18:18:37 +00:00
|
|
|
## Create a Minikube cluster
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2018-11-05 19:31:11 +00:00
|
|
|
1. Click **Launch Terminal**
|
2018-02-12 22:59:52 +00:00
|
|
|
|
2018-11-08 19:13:04 +00:00
|
|
|
{{< kat-button >}}
|
2018-02-12 22:59:52 +00:00
|
|
|
|
2018-11-08 19:13:04 +00:00
|
|
|
{{< note >}}If you installed Minikube locally, run `minikube start`.{{< /note >}}
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2018-11-05 19:31:11 +00:00
|
|
|
2. Open the Kubernetes dashboard in a browser:
|
2018-02-13 06:31:49 +00:00
|
|
|
|
2018-11-08 19:13:04 +00:00
|
|
|
```shell
|
|
|
|
minikube dashboard
|
|
|
|
```
|
2018-02-13 06:31:49 +00:00
|
|
|
|
2018-11-05 19:31:11 +00:00
|
|
|
3. Katacoda environment only: At the top of the terminal pane, click the plus sign, and then click **Select port to view on Host 1**.
|
2018-10-04 03:50:42 +00:00
|
|
|
|
2018-11-05 19:31:11 +00:00
|
|
|
4. Katacoda environment only: Type 30000, and then click **Display Port**.
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2017-01-18 18:18:37 +00:00
|
|
|
## Create a Deployment
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2017-04-19 17:56:47 +00:00
|
|
|
A Kubernetes [*Pod*](/docs/concepts/workloads/pods/pod/) is a group of one or more Containers,
|
2016-12-13 06:36:19 +00:00
|
|
|
tied together for the purposes of administration and networking. The Pod in this
|
|
|
|
tutorial has only one Container. A Kubernetes
|
2017-05-19 01:16:31 +00:00
|
|
|
[*Deployment*](/docs/concepts/workloads/controllers/deployment/) checks on the health of your
|
2016-12-13 06:36:19 +00:00
|
|
|
Pod and restarts the Pod's Container if it terminates. Deployments are the
|
|
|
|
recommended way to manage the creation and scaling of Pods.
|
|
|
|
|
2018-11-30 20:51:59 +00:00
|
|
|
1. Use the `kubectl create` command to create a Deployment that manages a Pod. The
|
2018-11-05 19:31:11 +00:00
|
|
|
Pod runs a Container based on the provided Docker image.
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2018-11-08 19:13:04 +00:00
|
|
|
```shell
|
2018-11-30 20:51:59 +00:00
|
|
|
kubectl create deployment hello-node --image=gcr.io/hello-minikube-zero-install/hello-node --port=8080
|
2018-11-08 19:13:04 +00:00
|
|
|
```
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2018-11-05 19:31:11 +00:00
|
|
|
2. View the Deployment:
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2018-11-08 19:13:04 +00:00
|
|
|
```shell
|
|
|
|
kubectl get deployments
|
|
|
|
```
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2018-11-08 19:13:04 +00:00
|
|
|
Output:
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2018-11-08 19:13:04 +00:00
|
|
|
```shell
|
|
|
|
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
|
|
|
|
hello-node 1 1 1 1 1m
|
|
|
|
```
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2018-11-05 19:31:11 +00:00
|
|
|
3. View the Pod:
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2018-11-08 19:13:04 +00:00
|
|
|
```shell
|
|
|
|
kubectl get pods
|
|
|
|
```
|
|
|
|
Output:
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2018-11-08 19:13:04 +00:00
|
|
|
```shell
|
|
|
|
NAME READY STATUS RESTARTS AGE
|
|
|
|
hello-node-5f76cf6ccf-br9b5 1/1 Running 0 1m
|
|
|
|
```
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2018-11-05 19:31:11 +00:00
|
|
|
4. View cluster events:
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2018-11-08 19:13:04 +00:00
|
|
|
```shell
|
|
|
|
kubectl get events
|
|
|
|
```
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2018-11-05 19:31:11 +00:00
|
|
|
5. View the `kubectl` configuration:
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2018-11-08 19:13:04 +00:00
|
|
|
```shell
|
|
|
|
kubectl config view
|
|
|
|
```
|
2018-11-05 19:31:11 +00:00
|
|
|
|
2018-11-08 19:13:04 +00:00
|
|
|
{{< note >}}For more information about `kubectl`commands, see the [kubectl overview](/docs/user-guide/kubectl-overview/).{{< /note >}}
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2017-01-18 18:18:37 +00:00
|
|
|
## Create a Service
|
2016-12-13 06:36:19 +00:00
|
|
|
|
|
|
|
By default, the Pod is only accessible by its internal IP address within the
|
|
|
|
Kubernetes cluster. To make the `hello-node` Container accessible from outside the
|
|
|
|
Kubernetes virtual network, you have to expose the Pod as a
|
2017-04-19 17:56:47 +00:00
|
|
|
Kubernetes [*Service*](/docs/concepts/services-networking/service/).
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2018-11-05 19:31:11 +00:00
|
|
|
1. Expose the Pod to the public internet using the `kubectl expose` command:
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2018-11-08 19:13:04 +00:00
|
|
|
```shell
|
|
|
|
kubectl expose deployment hello-node --type=LoadBalancer
|
|
|
|
```
|
2018-11-16 18:22:21 +00:00
|
|
|
|
|
|
|
The `--type=LoadBalancer` flag indicates that you want to expose your Service
|
|
|
|
outside of the cluster.
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2018-11-05 19:31:11 +00:00
|
|
|
2. View the Service you just created:
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2018-11-08 19:13:04 +00:00
|
|
|
```shell
|
|
|
|
kubectl get services
|
|
|
|
```
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2018-11-08 19:13:04 +00:00
|
|
|
Output:
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2018-11-08 19:13:04 +00:00
|
|
|
```shell
|
|
|
|
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
|
|
|
|
hello-node LoadBalancer 10.108.144.78 <pending> 8080:30369/TCP 21s
|
|
|
|
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 23m
|
|
|
|
```
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2018-11-16 18:22:21 +00:00
|
|
|
On cloud providers that support load balancers,
|
2018-11-08 19:13:04 +00:00
|
|
|
an external IP address would be provisioned to access the Service. On Minikube,
|
|
|
|
the `LoadBalancer` type makes the Service accessible through the `minikube service`
|
|
|
|
command.
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2018-11-05 19:31:11 +00:00
|
|
|
3. Run the following command:
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2018-11-08 19:13:04 +00:00
|
|
|
```shell
|
|
|
|
minikube service hello-node
|
|
|
|
```
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2018-11-08 19:13:04 +00:00
|
|
|
4. Katacoda environment only: Click the plus sign, and then click **Select port to view on Host 1**.
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2018-11-05 19:31:11 +00:00
|
|
|
5. Katacoda environment only: Type in the Port number following `8080:`, and then click **Display Port**.
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2018-11-08 19:13:04 +00:00
|
|
|
This opens up a browser window that serves your app and shows the "Hello World" message.
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2017-11-29 22:59:10 +00:00
|
|
|
## Enable addons
|
|
|
|
|
|
|
|
Minikube has a set of built-in addons that can be enabled, disabled and opened in the local Kubernetes environment.
|
|
|
|
|
2018-11-05 19:31:11 +00:00
|
|
|
1. List the currently supported addons:
|
2017-11-29 22:59:10 +00:00
|
|
|
|
2018-11-08 19:13:04 +00:00
|
|
|
```shell
|
|
|
|
minikube addons list
|
|
|
|
```
|
|
|
|
|
|
|
|
Output:
|
|
|
|
|
|
|
|
```shell
|
|
|
|
addon-manager: enabled
|
|
|
|
coredns: disabled
|
|
|
|
dashboard: enabled
|
|
|
|
default-storageclass: enabled
|
|
|
|
efk: disabled
|
|
|
|
freshpod: disabled
|
|
|
|
heapster: disabled
|
|
|
|
ingress: disabled
|
|
|
|
kube-dns: enabled
|
|
|
|
metrics-server: disabled
|
|
|
|
nvidia-driver-installer: disabled
|
|
|
|
nvidia-gpu-device-plugin: disabled
|
|
|
|
registry: disabled
|
|
|
|
registry-creds: disabled
|
|
|
|
storage-provisioner: enabled
|
|
|
|
```
|
|
|
|
|
2018-11-05 19:31:11 +00:00
|
|
|
2. Enable an addon, for example, `heapster`:
|
2017-11-29 22:59:10 +00:00
|
|
|
|
2018-11-08 19:13:04 +00:00
|
|
|
```shell
|
|
|
|
minikube addons enable heapster
|
|
|
|
```
|
2018-11-05 19:31:11 +00:00
|
|
|
|
2018-11-08 19:13:04 +00:00
|
|
|
Output:
|
2017-11-29 22:59:10 +00:00
|
|
|
|
2018-11-08 19:13:04 +00:00
|
|
|
```shell
|
|
|
|
heapster was successfully enabled
|
|
|
|
```
|
2017-11-29 22:59:10 +00:00
|
|
|
|
2018-11-05 19:31:11 +00:00
|
|
|
3. View the Pod and Service you just created:
|
2017-11-29 22:59:10 +00:00
|
|
|
|
2018-11-08 19:13:04 +00:00
|
|
|
```shell
|
|
|
|
kubectl get pod,svc -n kube-system
|
|
|
|
```
|
|
|
|
|
|
|
|
Output:
|
|
|
|
|
|
|
|
```shell
|
|
|
|
NAME READY STATUS RESTARTS AGE
|
|
|
|
pod/heapster-9jttx 1/1 Running 0 26s
|
|
|
|
pod/influxdb-grafana-b29w8 2/2 Running 0 26s
|
|
|
|
pod/kube-addon-manager-minikube 1/1 Running 0 34m
|
|
|
|
pod/kube-dns-6dcb57bcc8-gv7mw 3/3 Running 0 34m
|
|
|
|
pod/kubernetes-dashboard-5498ccf677-cgspw 1/1 Running 0 34m
|
|
|
|
pod/storage-provisioner 1/1 Running 0 34m
|
|
|
|
|
|
|
|
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
|
|
|
|
service/heapster ClusterIP 10.96.241.45 <none> 80/TCP 26s
|
|
|
|
service/kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP 34m
|
|
|
|
service/kubernetes-dashboard NodePort 10.109.29.1 <none> 80:30000/TCP 34m
|
|
|
|
service/monitoring-grafana NodePort 10.99.24.54 <none> 80:30002/TCP 26s
|
|
|
|
service/monitoring-influxdb ClusterIP 10.111.169.94 <none> 8083/TCP,8086/TCP 26s
|
|
|
|
```
|
2017-11-29 22:59:10 +00:00
|
|
|
|
2018-11-05 19:31:11 +00:00
|
|
|
4. Disable `heapster`:
|
2017-11-29 22:59:10 +00:00
|
|
|
|
2018-11-08 19:13:04 +00:00
|
|
|
```shell
|
|
|
|
minikube addons disable heapster
|
|
|
|
```
|
2018-11-05 19:31:11 +00:00
|
|
|
|
2018-11-08 19:13:04 +00:00
|
|
|
Output:
|
2017-11-29 22:59:10 +00:00
|
|
|
|
2018-11-08 19:13:04 +00:00
|
|
|
```shell
|
|
|
|
heapster was successfully disabled
|
|
|
|
```
|
2017-11-29 22:59:10 +00:00
|
|
|
|
2017-01-18 18:18:37 +00:00
|
|
|
## Clean up
|
2016-12-13 06:36:19 +00:00
|
|
|
|
|
|
|
Now you can clean up the resources you created in your cluster:
|
|
|
|
|
|
|
|
```shell
|
|
|
|
kubectl delete service hello-node
|
|
|
|
kubectl delete deployment hello-node
|
|
|
|
```
|
|
|
|
|
2018-11-16 18:22:21 +00:00
|
|
|
Optionally, stop the Minikube virtual machine (VM):
|
2016-12-13 06:36:19 +00:00
|
|
|
|
|
|
|
```shell
|
|
|
|
minikube stop
|
|
|
|
```
|
|
|
|
|
2017-11-29 22:59:10 +00:00
|
|
|
Optionally, delete the Minikube VM:
|
|
|
|
|
|
|
|
```shell
|
|
|
|
minikube delete
|
|
|
|
```
|
|
|
|
|
2018-05-05 16:00:51 +00:00
|
|
|
{{% /capture %}}
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2018-05-05 16:00:51 +00:00
|
|
|
{{% capture whatsnext %}}
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2017-04-19 17:56:47 +00:00
|
|
|
* Learn more about [Deployment objects](/docs/concepts/workloads/controllers/deployment/).
|
2016-12-30 04:54:29 +00:00
|
|
|
* Learn more about [Deploying applications](/docs/user-guide/deploying-applications/).
|
2017-04-19 17:56:47 +00:00
|
|
|
* Learn more about [Service objects](/docs/concepts/services-networking/service/).
|
2016-12-13 06:36:19 +00:00
|
|
|
|
2018-05-05 16:00:51 +00:00
|
|
|
{{% /capture %}}
|