Environment: centos7, docker18
minikube builds k8s
Description
minikube is the local stand-alone cluster closest to native kubernetes. It supports most kubernetes functions and is used for learning and developing k8s. Support Linux, Windows, Mac
Official website installation documentation
Installation prerequisites
- A physical machine or virtual machine, the physical machine CPU is greater than 2 core vcpu, 2G memory, and 20G disk. Here we take CentOS7.9.2009 as an example.
- Can connect to the Internet
- Including a container or virtual machine management engine, taking Docker as an example here
- Here we take a Linux server as an example, such as CentOS7.9.2003
Installation steps
Pre-operation (optional)
In order to reduce some problems that may be encountered when deploying minikube, it is recommended to install some operating system settings for native kubernets. The possible impact of not performing the following steps has not been verified at present. I will give opinions on the execution steps, please make your own choice. .
Upgrade the kernel (recommended)
Reason: It is recommended to use kernel 4.x or above when using Containerd, otherwise there will be a kernel version control warning
- Check the current kernel version. If it is lower than 4.x, it is recommended to upgrade.
awk -F\' '$1=="menuentry " {print i + + " : " $2}' /etc/grub2.cfg
- Add elrepo source
rpm -Uvh https://mirrors.aliyun.com/elrepo/elrepo/el7/x86_64/RPMS/elrepo-release-7.0-5.el7.elrepo.noarch.rpm
- Check which versions are available (optional, you can directly proceed to the next step to install the latest)
yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
- Install kernel
# Install the latest stable version
yum --enablerepo=elrepo-kernel install kernel-lt -y
#Install the specified version
yum --enablerepo=elrepo-kernel install kernel-lt-5.4.180-1.el7.elrepo -y
- Generate grub configuration file
grub2-mkconfig -o /boot/grub2/grub.cfg
- Check the available kernel versions again and change the boot order
# Change the startup sequence, where 0 is the serial number of the latest installed kernel
grub2-set-default 0
- Restart and check the current effective kernel version
#restart
reboot
#Check the effective kernel
uname -r
Upgrade docker
Reason: Newer versions of kubernetes require higher versions. The current official recommendation for minikube is 18.09 and above
- Check the current docker version. If it is lower than 18.09, continue to upgrade
docker version
- Uninstall the currently installed docker
yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate
- Docker-engine installs the yum-utils package and sets the repository
yum install -y yum-utils
yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum update -y
- Install a specific version of docker (optional)
# View currently available docker versions
yum list docker-ce --showduplicates | sort -r
#Install the specified version
yum install docker-ce-
docker-ce-cli- containerd.io docker-compose-plugin
# Install the latest version (recommended)
yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin
- Start docker and set up automatic startup
systemctl enable docker
systemctl start docker
Disable SELinux
Reason: The current kubelet does not support SElinux mode. Must be closed to allow the container to access the host file system and for the Pod network to work properly
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
Turn off the firewall (optional)
systemctl stop firewalld
Disable swap partition
Reason: Not disabling swap partitioning in native kubernetes will have a great impact on performance, and is inherited here
swapoff -a
sed -ri 's/.*swap.*/# & amp;/' /etc/fstab
Time synchronization (optional)
Note 1: You can use ntp or chronyd, and both cannot be used at the same time. Here we use chronyd as an example
Note 2: chronyd synchronizes the public server in the pool.ntp.org project by default, and can also synchronize other servers, such as Ali ntp server
yum -y install chrony
systemctl start chronyd
systemctl enable --now chronyd
# Synchronize time with public server
chronyc sources
Uninstall networkmanager (optional)
systemctl stop NetworkManager
yum remove NetworkManager -y
Install minikube
- Get minikube
- Start (basic command)
minikube start
- Recommended startup commands
minikube start --force --driver=docker --cni calico --image-mirror-country='cn' --container-runtime=containerd
Note 1: Install version 1.24.1 and above because kubernetes has abandoned dockershim and uses containerd as the CRI. Therefore, you must specify –container-runtime=containerd, otherwise kubelet cannot start normally. This is also the reason why higher versions cannot work properly on minikube. start, but the reason why it can be started if you specify a version lower than 1.24.1
Note 2: –image-mirror-country=’cn’ is to use the domestic Alibaba Cloud warehouse instead of the foreign Google warehouse to solve the problem of slow and blocked networks. In actual use (2023.3 2), it was found that the access to the Google warehouse was normal, and Alibaba When installing the latest kubernetes version in the cloud warehouse, some images are missing, so don’t add this parameter if you can.
Note 3: If –image-mirror-country=’cn’ still cannot pull the mirror, for example, when cni specifies the calico network and cannot pull the corresponding mirror, it is recommended to change –image-mirror-country=’cn ‘Replace with –registry-mirror=https://registry.docker-cn.com, the current test is feasible
Configure the dashboard as a fixed service and use proxy to proxy to the host machine
dashboard configuration yaml
vi kubernetes-dashboard-nodeport-svc.yaml
The configuration file is as follows
apiVersion: v1 Kind: Service metadata: name: kubernetes-dashboard-nodeport-svc namespace: kubernetes-dashboard labels: addonmanager.kubernetes.io/mode: Reconcile k8s-app: kubernetes-dashboard kubernetes.io/minikube-addons: dashboard spec: selector: k8s-app: kubernetes-dashboard type: NodePort ports: - protocol: TCP port: 9090 targetPort: 9090 nodePort: 30000
Start the dashboard service and enable the proxy, and test accessing the dashboard through the host IP.
#Create dashboard service kubectl apply -f kubernetes-dashboard-nodeport-svc.yaml #Start proxy service #kubectl expose deployment kubernetes-dashboard/kubernetes-dashboard-nodeport-svc --type=LoadBalancer --port=30000 kubectl proxy --address='0.0.0.0' --accept-hosts='^*$' --port=30000 & amp;
Open the address corresponding to the host IP:
http://172.168.12.128:30000/api/v1/namespaces/kubernetes-dashboard/services/kubernetes-dashboard-nodeport-svc/proxy
kubernetes-dashboard/kubernetes-dashboard-nodeport-svc
The page shown below is the dashboard page