# Download the latest version of Minikube curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 # Make the binary executable chmod +x ./minikube # Move the binary to your executable path sudo mv ./minikube /usr/local/bin/
安装所需依赖
安装 conntrack
1 2
# Install the conntrack package sudo apt install -y conntrack
#!/bin/bash if [ "$UID" != 0 ]; then echo"You need to run $0 through sudo" exit 1 fi SYSTEMD_PID="$(ps -ef | grep '/lib/systemd/systemd --system-unit=basic.target$' | grep -v unshare | awk '{print $2}')" if [ -z "$SYSTEMD_PID" ]; then /usr/sbin/daemonize /usr/bin/unshare --fork --pid --mount-proc /lib/systemd/systemd --system-unit=basic.target while [ -z "$SYSTEMD_PID" ]; do SYSTEMD_PID="$(ps -ef | grep '/lib/systemd/systemd --system-unit=basic.target$' | grep -v unshare | awk '{print $2}')" done fi if [ -n "$SYSTEMD_PID" ] && [ "$SYSTEMD_PID" != "1" ]; then if [ -n "$1" ] && [ "$1" != "bash --login" ] && [ "$1" != "/bin/bash --login" ]; then exec /usr/bin/nsenter -t "$SYSTEMD_PID" -a \ /usr/bin/sudo -H -u "$SUDO_USER" \ /bin/bash -c 'set -a; source "$HOME/.systemd-env"; set +a; exec bash -c '"$(printf "%q""$@")" else exec /usr/bin/nsenter -t "$SYSTEMD_PID" -a \ /bin/login -p -f "$SUDO_USER" \ $(/bin/cat "$HOME/.systemd-env" | grep -v "^PATH=") fi echo"Existential crisis" fi
Edit the permissions of the enter-systemd-namespace script
1
sudo chmod +x /usr/sbin/enter-systemd-namespace
Edit the bash.bashrc file
1
sudo sed -i 2a"# Start or enter a PID namespace in WSL2\nsource /usr/sbin/start-systemd-namespace\n" /etc/bash.bashrc
退出并重新启动WSL2会话
Minikube:单节点kubernetes集群
1 2 3 4 5 6 7 8
# Check if the KUBECONFIG is not set echo$KUBECONFIG # Check if the .kube directory is created > if not, no need to create it ls $HOME/.kube # Check if the .minikube directory is created > if yes, delete it ls $HOME/.minikube # Create the cluster with sudo minikube start --driver=none --image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers
设置非root用户能够使用kubectl
1 2 3 4 5 6 7
# Change the owner of the .kube and .minikube directories sudo chown -R $USER$HOME/.kube $HOME/.minikube # Check the access and if the cluster is running kubectl cluster-info # Check the resources created kubectl get all --all-namespaces
# Enable the Dashboard service sudo minikube dashboard # Access the Dashboard from a browser on Windows side
输出的地址即为Kubernetes Dashbord的访问地址,或使用如下命令查看地址:
1
minikube dashboard --url
通过LoadBalancer访问Dashboard
编辑Dashboard服务,并将其类型更改为LoadBalancer:
1 2 3 4 5 6 7 8
# Edit the Dashoard service kubectl edit service/kubernetes-dashboard --namespace kubernetes-dashboard # Go to the very end and remove the last 2 lines status: loadBalancer: {} # Change the type from ClusterIO to LoadBalancer type: LoadBalancer # Save the file
再次检查Dashboard服务
1 2 3
# Get all the services from the dashboard namespace kubectl get all --namespace kubernetes-dashboard # Access the Dashboard from a browser on Windows side with the URL: localhost:<port exposed>
测试:简单部署 nginx
创建一个部署和服务
1 2 3
kubectl create deployment nginx --image=nginx kubectl create service nodeport nginx --tcp 80:80 kubectl get pods,svc