[kubernetes] 使用 Minikube 快速搭建本地 k8s 环境 (基于 Docker 驱动模式)

时间:2021-02-08 04:26:25

一、实验环境

操作系统:Centos 7 x86_64

Docker:17.03.2-ce

二、部署 k8s 步骤

2.1 安装 kubectl

cat <<EOF > /etc/yum.repos.d/kubernetes.repo  
[kubernetes]  
name=Kubernetes  
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64  
enabled=1  
gpgcheck=0  
repo_gpgcheck=0  
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg  
       http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg  
EOF  

yum install -y kubectl  

2.2 安装 Minikube(使用阿里修改后的)

curl -Lo minikube http://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/releases/v0.26.1/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/

2.3 准备镜像

  • 本文使用阿里云docker镜像源,处理代码如下
#拉取镜像
docker pull registry.cn-beijing.aliyuncs.com/k8s_len/kube-proxy-amd64&& \
docker pull registry.cn-beijing.aliyuncs.com/k8s_len/kube-apiserver-amd64&& \
docker pull registry.cn-beijing.aliyuncs.com/k8s_len/kube-controller-manager-amd64&& \
docker pull registry.cn-beijing.aliyuncs.com/k8s_len/kube-scheduler-amd64&& \
docker pull registry.cn-beijing.aliyuncs.com/k8s_len/etcd-amd64&& \
docker pull registry.cn-beijing.aliyuncs.com/k8s_len/k8s-dns-kube-dns-amd64&& \
docker pull registry.cn-beijing.aliyuncs.com/k8s_len/k8s-dns-sidecar-amd64&& \
docker pull registry.cn-beijing.aliyuncs.com/k8s_len/k8s-dns-dnsmasq-nanny-amd64&& \
docker pull registry.cn-beijing.aliyuncs.com/k8s_len/pause-amd64&& \
docker pull registry.cn-beijing.aliyuncs.com/k8s_len/kubernetes-dashboard-amd64&& \
docker pull registry.cn-hangzhou.aliyuncs.com/yandaxin/openfaas-kube-addon-manager-amd64&& \
docker pull registry.cn-hangzhou.aliyuncs.com/dck8s/storage-provisioner

#重命名镜像 
docker tag registry.cn-beijing.aliyuncs.com/k8s_len/kube-apiserver-amd64 k8s.gcr.io/kube-apiserver-amd64&& \
docker tag registry.cn-beijing.aliyuncs.com/k8s_len/kube-controller-manager-amd64 k8s.gcr.io/kube-controller-manager-amd64&& \
docker tag registry.cn-beijing.aliyuncs.com/k8s_len/kube-scheduler-amd64 k8s.gcr.io/kube-scheduler-amd64&& \
docker tag registry.cn-beijing.aliyuncs.com/k8s_len/etcd-amd64 k8s.gcr.io/etcd-amd64&& \
docker tag registry.cn-beijing.aliyuncs.com/k8s_len/k8s-dns-kube-dns-amd64 k8s.gcr.io/k8s-dns-kube-dns-amd64&& \
docker tag registry.cn-beijing.aliyuncs.com/k8s_len/k8s-dns-sidecar-amd64 k8s.gcr.io/k8s-dns-sidecar-amd64&& \
docker tag registry.cn-beijing.aliyuncs.com/k8s_len/k8s-dns-dnsmasq-nanny-amd64 k8s.gcr.io/k8s-dns-dnsmasq-nanny-amd64&& \
docker tag registry.cn-beijing.aliyuncs.com/k8s_len/pause-amd64 k8s.gcr.io/pause-amd64&& \
docker tag registry.cn-beijing.aliyuncs.com/k8s_len/kube-proxy-amd64 k8s.gcr.io/kube-proxy-amd64&& \
docker tag registry.cn-beijing.aliyuncs.com/k8s_len/kubernetes-dashboard-amd64 k8s.gcr.io/kubernetes-dashboard-amd64&& \
docker tag registry.cn-hangzhou.aliyuncs.com/yandaxin/openfaas-kube-addon-manager-amd64 k8s.gcr.io/kube-addon-manager&& \
docker tag registry.cn-hangzhou.aliyuncs.com/dck8s/storage-provisioner gcr.io/k8s-minikube/storage-provisioner

2.4 启动 k8s 服务

minikube start --vm-driver=none  

2.5 检查服务是否正常

kubectl get node

#status为Ready即为正常

2.6 配置 dashboard

minikube dashboard

2.7 查看 dashboard

打开浏览器,访问:http://<你机器IP地址>:30000

2.8 如何启停集群

minikube start/stop

2.9 如何删除集群

minikube delete  
rm -rf ~/.minikube  
kubeadm reset