[Cloud Native | K8s Series Part 2]: Use MiniKube to create the first K8s cluster

foreword

This article is the second in the K8s series. I have written many column articles about cloud native before. Interested students can access it through any door: cloud native column .

insert image description here

Objectives of this article:

  • Learn about Kubernetes clusters.
  • Learn about MiniKube.
  • Create your first Kubernetes cluster with MiniKube~

1. Introduction to K8s cluster

Kubernetes coordinates a cluster of highly available computers, each of which works as an independent unit connected to each other. The abstractions in Kubernetes allow containerized applications to be deployed to clusters without tying them to a specific standalone computer. In order to use this new deployment model, applications need to be packaged in a way that separates them from a single host: they need to be containerized. Containerized applications are more flexible and usable than past deployment models where applications are deeply integrated with the host directly in packages. Kubernetes automatically distributes and schedules application containers across clusters in a more efficient manner. Kubernetes is an open source platform and can be used in production environments.

A Kubernetes cluster contains two types of resources:

  • Master schedules the entire cluster
  • Nodes are responsible for running the application

insert image description here
The Master is responsible for managing the entire cluster. The Master coordinates all activities in the cluster, such as scheduling applications, maintaining the desired state of applications, scaling applications, and rolling out new updates.

Node is a virtual machine or physical machine, which acts as a worker machine in a Kubernetes cluster. Each Node has a Kubelet, which manages Node and acts as an agent for Node to communicate with Master. Node should also have tools for handling container operations, such as Docker. A Kubernetes cluster handling production-grade traffic should have at least three Nodes, because if a Node fails its corresponding etcd members and control plane instances are lost, and redundancy suffers.

When deploying an application on Kubernetes, tell the Master to start the application container. The master orchestrates the containers to run on the nodes of the cluster. Node communicates with the Master using the Kubernetes API exposed by the Master. End users can also interact with the cluster using the Kubernetes API.

Kubernetes can be deployed on both physical and virtual machines. You can start deploying a Kubernetes cluster using Minikube.

2. What is MiniKube

insert image description here

Kubernetes can be deployed on both physical and virtual machines. You can start deploying a Kubernetes cluster using Minikube.

  • Minikube is a lightweight Kubernetes implementation that creates VMs on your local machine and deploys a simple one-node cluster. Minikube is available for Linux, macOS and Windows systems. Minikube CLI provides various operations for bootstrapping cluster work, including start, stop, view status, and delete.

In fact, in MiniKube, the Master node is integrated with other nodes, and the whole is managed by kubectl on the host, which can save more resources.

3. The working principle of MiniKube

insert image description here
The A/B/C/D in the above figure are:

  • A: Minikube generates kubeconfig configuration file locally on PC
  • B: Minikube Create a Minikube virtual machine in a virtual environment
  • C: Minikube builds Kubernetes in a virtual machine
  • D: Kubectl manages Kubernetes in virtual machines through kubeconfig

4. Use MiniKube to create a K8s cluster

1. Set up and run the cluster

Assuming that MniKube has been successfully installed, now check the MiniKube version:

$ minikube version

Start MiniKube:

minikube start

insert image description here

2. Use the command line interface kubectl to operate

Check out the Kubectl version command:

kubectl version
$ kubectl version
Client Version: version.Info{
    
    Major:"1", Minor:"20",GitVersion:"v1.20.4",
GitCommit:"e87da0bd6e03ec3fea7933c4b5263d151aafd07c", 
GitTreeState:"clean", BuildDate:"2021-02-18T16:12:00Z", GoVersion:"go1.15.8", 
Compiler:"gc", Platform:"linux/amd64"}

insert image description here

3. View cluster information

View cluster details

kubectl cluster-info

insert image description here

4. Query the node information in the cluster

kubectl get nodes //查询所有节点
kubectl get node -A  //查询单个节点

This command displays all nodes available to host the application. Now that we only have one node, we can see that its state is ready (it is ready to accept applications for deployment).

insert image description here

Summarize

In the previous step, the process of using MiniKube to create the first K8s cluster is over, which is very simple.

In this article, we learned about Kubernetes clusters, learned about MiniKube, and used MiniKube to create the first Kubernetes cluster.

In the next article in the K8s series, we will learn how to deploy applications, how to understand applications and other practical operations.

The difference between MiniKube and K8s cluster

Usually, a complete set of Kubernetes cluster needs to include at least master node and node node. The following figure shows the cluster architecture of conventional k8s. The master node is generally independent and is used to coordinate and debug other nodes, and the actual operation of the container is On the node node, kubectl is located on the master node.

insert image description here
The following figure is the architecture of Minikube, in which the master node is integrated with other nodes, and the whole is managed by kubectl on the host, which can save resources more.

insert image description here

List of MiniKube Commands

Access the Kubernetes dashboard running in the minikube cluster:

minikube dashboard

Once launched, you can interact with your cluster using kubectl just like any other Kubernetes cluster. For example, to start the server:

kubectl create deployment hello-minikube --image=k8s.gcr.io/echoserver:1.4

Expose service as NodePort

kubectl expose deployment hello-minikube --type=NodePort --port=8080

minikube can easily open this exposed endpoint in a browser:

minikube service hello-minikube

Stop and delete the local cluster

minikube stop/delete

Delete all local clusters and configuration files

minikube delete --all

Guess you like

Origin blog.csdn.net/weixin_51484460/article/details/125592377