1. Description
This article mainly introduces the rapid deployment of Kubernetes single-node cluster environment based on Minikube in the Centos7 environment, and accessing the dashboard service deployed on k8s on the browser.
two, minikube introduction
Minikube
is a go-based tool that is easy to run Kubernetes locally. It can easily create a stand-alone Kubernetes cluster in a virtual machine on your laptop without high requirements on hardware resources. Great for testing and local development.
Official documentation: Welcome! | minikube
Architecture diagram:
How it works:
It can be seen from the architecture of Minikube that the master node is integrated with other nodes, and the whole is managed by kubectl on the host machine, which can save more resources.
To put it simply, users use Minikube CLI to manage the Kubernetes environment on the virtual machine, such as: start, stop, delete, get status, etc. Once the Minikube VM is started, users can use the familiar Kubectl CLI to perform operations on the Kubernetes cluster.
Three, Minikube installation
3.1. System Requirements
- CPU: more than 2 cores
- Memory: 2GB or more
- Hard disk: need 20G
- Network: able to connect to the Internet (need to download the installation package),
- Containers: Docker or other containers need to be installed first.
3.2. Preparation before installation
3.2.1. Install Docker
Installation steps reference: CentOS Docker installation | rookie tutorial
The minimum recommended version of docker is 20.10.0 and above
Configure Alibaba Cloud Accelerator: Alibaba Cloud Login – Welcome to Alibaba Cloud, a secure and stable cloud computing service platform
Start docker:
systemctl start docker systemctl enable docker.service
3.2.2. Create a new user
-
Operating minikube requires a user with root privileges (non-root)
-
The user needs to be added to the docker user group
- Add this user to the docker user group:
sudo gpasswd -a username docker
- Update the docker user group:
newgrp docker
- Add this user to the docker user group:
3.3. Deployment
Switch the newly created user to operate minikube, the user I created here is zlt
su zlt
Installation steps reference: minikube start | minikube
3.3.1. Installation commands
Execute the following 2 commands to download and install the minikube command:
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 sudo install minikube-linux-amd64 /usr/local/bin/minikube
Execute the command minikube version
to view the version number:
3.3.2. Start the cluster
Execute the following command:
minikube start --image-mirror-country='cn' --kubernetes-version=v1.23.8
image-mirror-country specifies the use of domestic sources
kubernetes-version specifies the deployed version (the latest version has many compatibility pits, so choose a lower version)
The execution is successful as shown in the figure below:
3.3.3. Authentication
Execute the command minikube status
to view the status, the results are as follows:
[zlt@zlt opt]$ minikube status minikube type: Control Plane host: Running kubelet: Running apiserver: Running kubeconfig: Configured
3.3.4. View cluster status
You can directly use the kubectl command that comes with minikube.
Get all nodes (machines) in the cluster:
minikube kubectl get nodes
Get all namespaces of the cluster:
minikube kubectl get namespaces
View all Pods in the cluster:
minikube kubectl --get pods -A
3.3.5. Minikube common commands
Enter the node server:
minikube ssh
Execute node server commands, such as viewing node docker info:
minikube ssh -- docker info
To delete the cluster, delete the files cached in the ~/.minikube directory:
minikube delete
Shut down the cluster:
minikube stop
Destroy the cluster:
minikube stop & amp; & amp; minikube delete
four, install kubectl
Since the built-in kubectl command of minikube is not fully functional, it is best to install a kubectl
independently
Download the latest release with the following command:
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/ kubectl"
Install kubectl:
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
View version details:
kubectl version --client --output=yaml
Five, install dashboard
Execute the following command to start the dashboard plugin:
minikube dashboard
If you want to directly access the dashboard outside the cluster, you need to set up a proxy to access it. Execute the following command:
kubectl proxy --port=8001 --address='192.168.28.138' --accept-hosts='^.*'
–port The port number that needs to be exposed
–address server external network IP (host IP)
–accept-hosts IPs of external access servers (whitelist)
This will allow you to access the Kubernetes Dashboard on your browser at:
http://192.168.28.138:8001/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/