Chat Zalo Chat Messenger Phone Number Đăng nhập
Hello Minikube - Kubernetes

Hello Minikube – Kubernetes

This tutorial shows how to run a sample application on Kubernetes using minikube. The tutorial provides a container image that uses NGINX to echo all requests.

  • Objectives Deploy a sample application to
  • minikube.

  • Run the
  • application.

  • View application logs

.

Before you begin

This tutorial assumes that you have already set up minikube. See starting minikube for installation instructions.

You also need to install kubectl. See Install tools for installation instructions.

Create a minikube cluster

Open the dashboard

Open the

Kubernetes dashboard. You can do this in two different ways:

  • Start
  • a browser URL

  • copy and paste

Create a deployment A

Kubernetes pod is a group of one or more containers, linked together for management and networking purposes. The Pod in this tutorial has only one container. A Kubernetes deployment checks the health of its Pod and restarts the Pod container if it terminates. Deployments are the recommended way to manage pod creation and scaling.

  1. Use the kubectl create command to create a deployment that manages a pod. The Pod runs a container based on the provided Docker image.

  2. View the deployment:The output is similar to:NAME READY TO DATE AVAILABLE AGE hello-node 1/1 1 1 1m View pod:

  3. Output is similar to

    :NAME READY STATE REBOOT AGE hello-node-5f76cf6ccf-br9b5 1/1 Running 0 1m View cluster events:View configuration kubectl:

Creating a service

By default, the Pod can only be accessed by its internal IP address within the Kubernetes cluster. For the hello-node container to be accessible from outside the Kubernetes virtual network, you must expose the pod as a Kubernetes service.

  1. Expose the Pod to the public Internet by using the kubectl expose command:

    The

    -type=LoadBalancer flag indicates that you want to expose the service outside the cluster

    .

    The application code inside the test image only listens on TCP port 8080. If you used kubectl expose to expose a different port, clients could not connect to that other port.

  2. View the service

  3. you created

    :

    The output is similar

    to: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

    For cloud providers that support load balancers, an external IP address would be provisioned to access the service. In minikube, the LoadBalancer type makes the service accessible through the minikube service command.

  4. Run the following command:

    This opens a browser window that serves your application and displays the application’s response.

Enable add-ons

The

minikube tool includes a set of built-in plugins that can be enabled, disabled, and opened on-premises in the Kubernetes environment.

  1. List the currently supported plugins

    :

    The output is similar to

    :addon-manager: panel enabled: enabled default-storageclass: enabled EFK: disabled freshpod: disabled gvisor: disabled helm-tiller: disabled Ingress: disabled ingress-dns: Disabled LogViewer: Disabled Metrics-Server: Disabled NVIDIA-Driver-Installer: Disabled NVIDIA-GPU-Device-Plugin: Disabled Registration: Disabled Logging -Creds: Disabled Storage-Provisioner: Enabled Storage-Provisioner-Gluster: Disabled

  2. Enable a plugin, for example, metrics-server:The output is similar to:The ‘metrics-server’ plugin is enabled View the pod and service you created by installing that plugin:The result

  3. is similar to:

    NAME READY STATUS RESTARTS AGE pod/coredns-5644d7b6d9-mh9ll 1/1 Running 0 34m pod/coredns-5644d7b6d9-pqd2t 1/1 Running 0 34m pod/

    metrics-server-67fb648c5

  4. 1/1 Running 0 26s pod/etcd-minikube 1/1 Running 0 34m pod/influxdb-grafana-b29w8 2/2 Running 0 26s pod/kube-addon-manager-minikube 1/1 Running 0 34m pod/kube-apiserver-minikube 1/1 Running 0 34m pod/kube-controller-manager-minikube 1/1

  5. Running 0 34m

    pod

    /kube-proxy-rnlps 1/1 Running 0 34m pod/kube-scheduler-minikube 1/1 Running 0 34m pod/storage-provisioner 1/1 Running 0 34m NAME TYPE NAME CLUSTER-EXTERNAL IP-PORT(S) AGE service/metrics-server ClusterIP 10.96.241.45 <none> 80/TCP 26s service/kube-dns ClusterIP 10.96.0.10 <none> 53/UDP, 53/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

  6. Disable metrics-server:

  7. The result is similar

    to:

    metrics-server

    was successfully disabled

Cleanup

You can now clean up the resources you created in your

cluster:Stop Minikube cluster Optionally, delete the Minikube virtual machine

:

If you want to use minikube again to learn more about Kubernetes, you don’t need to delete it.

More

  • Information about deployment objects.
  • Learn more about app deployment.
  • Learn more about service objects.

Contact US