参考:
https://yq.aliyun.com/articles/221687
https://kubernetes.io/docs/tasks/tools/install-minikube/
首先准备一台centos7虚拟机(至少2核,2G内存,20G存储)。
先决条件
检查虚拟化是否开启(输出非空):
egrep --color 'vmx|svm' /proc/cpuinfo
安装 kubectl
先配置yum源,再安装kubectl。
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF
yum install -y kubectl
安装minibuke:
curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 \
&& chmod +x minikube
sudo cp minikube /usr/local/bin && rm minikube
安装docker:
yum install docker
运行minikube
minikube start --registry-mirror=https://registry.docker-cn.com --vm-driver=none
输出信息:
xxx
===================
WARNING: IT IS RECOMMENDED NOT TO RUN THE NONE DRIVER ON PERSONAL WORKSTATIONS
The 'none' driver will run an insecure kubernetes apiserver as root that may leave the host vulnerable to CSRF attacks
When using the none driver, the kubectl config and credentials generated will be root owned and will appear in the root home directory.
You will need to move the files to the appropriate location and then set the correct permissions. An example of this is below:
sudo mv /root/.kube $HOME/.kube # this will write over any previous configuration
sudo chown -R $USER $HOME/.kube
sudo chgrp -R $USER $HOME/.kube
sudo mv /root/.minikube $HOME/.minikube # this will write over any previous configuration
sudo chown -R $USER $HOME/.minikube
sudo chgrp -R $USER $HOME/.minikube
This can also be done automatically by setting the env var CHANGE_MINIKUBE_NONE_USER=true
Loading cached images from config file.
启动
缺省Minikube使用VirtualBox驱动来创建Kubernetes本地环境
minikube start --registry-mirror=https://registry.docker-cn.com
--vm-driver:默认virtualbox
none:none 驱动会运行一个不安全的API Server,会导致安全隐患,不建议在个人工作环境安装。
KVM2: 推荐linux使用
virtualbox:推荐Windows使用
启动后,使用kubectl
进行交互。例如,启动服务:
kubectl run hello-minikube --image=k8s.gcr.io/echoserver:1.4 --port=8080
kubectl get pod
暴露服务:
kubectl expose deployment hello-minikube --type=NodePort
在浏览器中打开该服务(需要在虚拟机中进行,而不是远程命令行):
minikube service hello-minikube
停止本地群集:
minikube stop
删除本地群集:
minikube delete
打开Kubernetes控制台(需要在虚拟机中进行,而不是远程命令行):
minikube dashboard