kubernetes-9-minikube install a local single node k8s cluster

Manually build k8s, complicated authentication, and high error rate in the configuration link. Minikube is a tool derived to solve this problem. It is developed based on the go language and can quickly build a usable k8s cluster in a stand-alone environment. It is very suitable for testing and local development. , Most of the existing online k8s experimental environments are also based on minikube.
Insert picture description hereMinikube is a set of tools provided by K8S official for developers to run K8S on personal computers. The implementation is written in the Go language, and a single-node cluster running in a virtual machine is created by calling the virtualization hypervisor.
Insert picture description here

(1) Environmental requirements
windows 10
minikube 1.16.0
kubernetes 17.3

1 windows10 underwear minikube

Download the installation package https://storage.googleapis.com/minikube/releases/latest/minikube-installer.exe.
Installation location D:\s\Minikube
CMD>minikube version【V1.16.0】
Insert picture description here

2 Use Hyper-V driver

Minikube provides the ability to build k8s across platforms, supports mac, linux, windows platforms, and supports multiple driver architectures on each platform. Windows supports docker, hyper-V, virtualBox, etc., because win10 has built-in Hyper-V, here Choose Hyper-v.

(1) Control Panel -> Programs -> Programs and Features -> Enable or disable Windows functions.
Insert picture description hereFollow the prompts to restart the computer.

(2) Hyper-V Manager
Virtual Switch Manager
Insert picture description here

2.1 Create a virtual switch

Insert picture description hereInput attributes
Insert picture description here

2.2 Create k8s

(1) Official website order

minikube start --driver=hyperv   --hyperv-virtual-switch="minikube"

Due to network reasons, creation with official website sources may always fail.
(2) Use domestic mirrors
to open CMD with administrator rights

minikube start  image-mirror-country='cn' --registry-mirror=https://registry.docker-cn.com --vm-driver="hyperv" --memory=4096 --hyperv-virtual-switch="minikube" --image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers

Option description:

--vm-driver 如果不写会自动检测,可选值 virtualbox, vmwarefusion, hyperv, vmware。
--image-mirror-country 需要使用的镜像镜像的国家/地区代码。留空以使用全球代码。对于中国大陆用户,请将其设置为 cn。
--image-repository 用来拉取 Kubernetes 集群所需镜像的仓库。
--registry-mirror 是docker registry 的镜像源,集群安装后拉取镜像加速用,可以使用其它加速器地址。
--memory 虚机内存大小

It takes a while to pull out the mirror, build a cluster, and wait patiently.
Insert picture description here

(3) Check the cluster status.
Under normal circumstances, wait for a period of time before the cluster is successfully set up. Run the following command to check the cluster status.
The first execution will install the kubectl of the windows platform, and then execute it after installation, you can see that the cluster is ready.
C:\Users\user.minikube\cache\windows\v1.20.0\kubectl.exe
check Node status
CMD>minikube kubectl get nodes
Insert picture description here
This k8s stand-alone cluster is completed.

2.3 Manage k8s

(1) Open the dashboard, visit the management page, it will automatically open
CMD>minikube dashboard
Insert picture description here http://127.0.0.1:1538/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/.

(2) Check the cluster status
CMD>minikube kubectl cluster-info
Insert picture description here
(3) Use ssh to enter the Minikube virtual machine
CMD>minikube ssh
Insert picture description here $ exit to logout logout

(4) Stop the running kubernetes cluster
CMD>minikube stop
Insert picture description here will shut down the created virtual machine
Insert picture description here

(5) Start the existing kubernetes cluster
CMD>minikube start
Insert picture description here
(6) Delete the local kubernetes cluster
CMD>minikube delete

(7) View the installed components
CMD>>minikube addons list,
for example, install and enable dashboard add-ons by default on minikube.
Insert picture description here

2.4 Use k8s

(1) File hello-application.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-world
spec:
  selector:
    matchLabels:
      run: load-balancer-example
  replicas: 2
  template:
    metadata:
      labels:
        run: load-balancer-example
    spec:
      containers:
        - name: hello-world
          image: registry.cn-hangzhou.aliyuncs.com/aliyun_google/google-sample-node-hello:1.0
          ports:
            - containerPort: 8080
              protocol: TCP

This file briefly describes the properties of a k8s deployment resource, including a deployment, a replicaSets, each replicaSets contains two Pods, each Pod runs a container, the mirror source of the container is registry.cn-hangzhou.aliyuncs.com/ aliyun_google/google-sample-node-hello:1.0, container port 8080.
(2) Start the application
Because there is no environment variable configured, you need to switch the directory C:\Users\user.minikube\cache\windows\v1.20.0\kubectl.exe.
CMD>kubectl.exe apply -f C:\Users\user\Desktop\hello-application.yaml
CMD>kubectl.exe get deployment
CMD>kubectl.exe describe deployment hello-world
CMD>kubectl.exe get pods
CMD>kubectl. exe describe pod hello-world-68fdbf5747-4gsgb
CMD>>kubectl.exe delete -f C:\Users\user\Desktop\hello-application.yaml
Insert picture description here(3)
Expose the application access entry The service exposure method is NodePort
CMD>kubectl.exe deployment expose hello-world --type=NodePort --name=node-service
CMD>kubectl.exe get service node-service
CMD>kubectl.exe describe service The node-service
Insert picture description hereservice is mapped to port 8080 of the container through port 32053, so that we can access the web application in the container through port 32053.
Host
Insert picture description herevirtual machine
Insert picture description herehttp://192.168.43.120:32053/
Insert picture description here

2.5 Analysis

(1) Minikube created a virtual machine to build a linux environment
Insert picture description here(2) Container
CMD>minikube ssh login,
$docker ps can see many running containers, including web applications, k8s dashboard, etcd, coredns, storage , Scheduler, apiserever, controller, etc.
$docker images

Insert picture description here
(3) If you need to update minikube, you need to update the minikube installation package
CMD>minikube delete Delete the existing virtual machine
Delete the file cached in the ~/.minikube directory C:\Users\user.minikube
Recreate the minikube environment
Insert picture description here

3 Use VirtualBox driver

Since minikube reuses docker-machine, the corresponding VirtualBox and VMware Fusion drivers are already supported in its software package.

VT-x/AMD-v virtualization must be enabled in the BIOS.

In Windows environment, if Hyper-V is turned on, VirtualBox mode is not supported.

(1) Go to close the hyper-v service (choose to manually start and close the service), and uncheck hyper-v in the control panel-program-start or close the program function.
(2) VERR_NEM_VM_CREATE_FAILED
must start the window command window as an administrator and run
CMD>bcdedit /set hypervisorlaunchtype off. If you do not start the command window as an administrator, running the above command will prompt the problem of inoperability because of insufficient authority.
(3) Restart the computer

3.1 Install virtualbox software in windows

3.2 Create k8s

(1) First, clear the created Hyper-V-based environment
CMD>minikube delete
(2) Install k8s

minikube start  image-mirror-country='cn' --registry-mirror=https://registry.docker-cn.com --vm-driver="virtualbox" --memory=4096 --image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers

Insert picture description here
A virtual machine based on virtualBox will be created automatically.
Insert picture description here

3.3 Manage k8s

Insert picture description here
Insert picture description here
Log in to the virtual machine from the host IP and check the IP address
Insert picture description here
. The username of the virtual machine minikube is the docker password tcuser.
IP192.168.99.100.
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_20466211/article/details/107591687