使用minikube创建K8S单机环境-填坑指南

云计算 温馨提示

此篇博文主要是记录如何在本地环境使用CentOS系统安装minikube,对于安装过程中大量出现镜像下载失败的问题做了填坑,主要是使用kubernete 1.12.1版本,对于其他不同版本,方法是一样的。

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:申请域名、网页空间、营销软件、网站建设、馆陶网站维护、网站推广。1.下载部署安装包
wget https://storage.googleapis.com/minikube/releases/v0.30.0/minikube-linux-amd64
mv minikube-linux-amd64  /usr/bin/minikube

wget https://dl.k8s.io/v1.12.1/kubernetes-server-linux-amd64.tar.gz
tar xf kubernetes-server-linux-amd64.tar.gz && cd kubernetes/server/bin/
cp kubectl kubeadm kubelet /usr/local/bin/
2.安装docker

上传docker-ce-17.03.2.ce-1.el7.centos.x86_64.rpmdocker-ce-selinux-17.03.2.ce-1.el7.centos.noarch.rpm到服务器,运行如下命令安装docker:

yum install docker-ce-selinux-17.03.2.ce-1.el7.centos.noarch.rpm -y
yum install docker-ce-17.03.2.ce-1.el7.centos.x86_64.rpm -y

启动docker服务,并将docker设置为开机自启动:

systemctl start docker
systemctl enable docker
3.下载kubernetes的docker镜像

创建如下脚本:

vi auto_pull_images.sh

在脚本中添加如下内容:

#!/bin/bash
images=(kube-proxy-amd64:v1.12.1 kube-scheduler-amd64:v1.12.1 kube-controller-manager-amd64:v1.12.1 kube-apiserver-amd64:v1.12.1 etcd-amd64:3.2.24  pause-amd64:3.1 kubernetes-dashboard-amd64:v1.10.0 k8s-dns-sidecar-amd64:1.14.8 k8s-dns-kube-dns-amd64:1.14.8
k8s-dns-dnsmasq-nanny-amd64:1.14.8)
for imageName in ${images[@]} ; do
  docker pull mirrorgooglecontainers/$imageName
  docker tag mirrorgooglecontainers/$imageName k8s.gcr.io/$imageName
  docker rmi mirrorgooglecontainers/$imageName
done

for n in $(docker images|awk \'{print $1:$2}\'|grep -v REPOSITORY); do docker tag $n  `echo $n|sed \'s/-amd64//g\'` && docker rmi $n; done
docker tag k8s.gcr.io/kubernetes-dashboard:v1.10.0  k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.0

docker pull coredns/coredns:1.2.2 
docker tag coredns/coredns:1.2.2 k8s.gcr.io/coredns:1.2.2
docker rmi coredns/coredns:1.2.2

docker pull registry.cn-hangzhou.aliyuncs.com/anoy/kube-addon-manager:v8.6
docker tag  registry.cn-hangzhou.aliyuncs.com/anoy/kube-addon-manager:v8.6  k8s.gcr.io/kube-addon-manager:v8.6
docker rmi registry.cn-hangzhou.aliyuncs.com/anoy/kube-addon-manager:v8.6

docker pull registry.cn-hangzhou.aliyuncs.com/anoy/storage-provisioner:v1.8.1
docker tag registry.cn-hangzhou.aliyuncs.com/anoy/storage-provisioner:v1.8.1 gcr.io/k8s-minikube/storage-provisioner:v1.8.1
docker rmi registry.cn-hangzhou.aliyuncs.com/anoy/storage-provisioner:v1.8.1

运行脚本:

sh auto_pull_images.sh

等待脚本运行成功后,执行如下命令,确认所需镜像已经下载到本地:

[root@node-2 ~]# docker images
REPOSITORY                                TAG                 IMAGE ID            CREATED             SIZE
k8s.gcr.io/kube-proxy                     v1.12.1             61afff57f010        2 weeks ago         96.6 MB
k8s.gcr.io/kube-apiserver                 v1.12.1             dcb029b5e3ad        2 weeks ago         194 MB
k8s.gcr.io/kube-scheduler                 v1.12.1             d773ad20fd80        2 weeks ago         58.3 MB
k8s.gcr.io/kube-controller-manager        v1.12.1             aa2dd57c7329        2 weeks ago         164 MB
k8s.gcr.io/etcd                           3.2.24              3cab8e1b9802        5 weeks ago         220 MB
k8s.gcr.io/coredns                        1.2.2               367cdc8433a4        8 weeks ago         39.2 MB
k8s.gcr.io/kubernetes-dashboard-amd64     v1.10.0             0dab2435c100        2 months ago        122 MB
k8s.gcr.io/kube-addon-manager             v8.6                9c16409588eb        8 months ago        78.4 MB
k8s.gcr.io/kubernetes-dashboard           v1.8.3              0c60bcf89900        8 months ago        102 MB
k8s.gcr.io/k8s-dns-dnsmasq-nanny          1.14.8              c2ce1ffb51ed        9 months ago        40.9 MB
k8s.gcr.io/k8s-dns-sidecar                1.14.8              6f7f2dc7fab5        9 months ago        42.2 MB
k8s.gcr.io/k8s-dns-kube-dns               1.14.8              80cc5ea4b547        9 months ago        50.5 MB
k8s.gcr.io/pause                          3.1                 da86e6ba6ca1        10 months ago       742 kB
gcr.io/k8s-minikube/storage-provisioner   v1.8.1              4689081edb10        11 months ago       80.8 MB
4.启动服务

启动minikube集群

minikube start --vm-driver=none --registry-mirror=https://registry.docker-cn.com --kubernetes-version v1.12.1

启动dashboard:

minikube dashboard

为dashboard添加外部访问代理,此处的IP为本地系统IP:

kubectl proxy  --port=8001 --address=\'10.0.0.2\' --accept-hosts=\'^.*\' &

通过url: http://10.0.0.2:8001/api/v1/namespaces/kube-system/services/http:kubernetes-dashboard:/proxy/ 访问dashboard。


分享文章:使用minikube创建K8S单机环境-填坑指南
本文地址:http://cdiso.cn/article/cgejgp.html

其他资讯