centos7.5+使用minikube安装kubernetes(k8s)
centos7.5+,都可以使用minikube安装kubernetes(k8s),信息如下(参考链接:https://developer.aliyun.com/article/779813?spm=a2c6h.14164896.0.0.5de64b8aiZ7smp)1、安装docker(参考官网链接 https://docs.docker.com/engine/install/centos/;
·
centos7.5+,都可以使用minikube安装kubernetes(k8s),信息如下(参考链接:https://developer.aliyun.com/article/779813?spm=a2c6h.14164896.0.0.5de64b8aiZ7smp)
1、安装docker(参考官网链接 https://docs.docker.com/engine/install/centos/ ; 阿里云docker镜像站 https://developer.aliyun.com/article/110806)
$ sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
- 配置国内公共镜像,修改 /etc/docker/daemon.json 文件并添加上 registry-mirrors 键值(官方链接 https://developer.aliyun.com/article/779813?spm=a2c6h.14164896.0.0.5de64b8aiZ7smp)
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://xxxxxx.mirror.aliyuncs.com"]
}
EOF
#注:访问阿里云镜像服务获取容器镜像加速地址,替换掉xxxxxx
#获取容器镜像加速链接 https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors?spm=a2c6h.12873639.0.0.6c236235IWJdCd
# step 1: 安装必要的一些系统工具
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
# Step 2: 添加软件源信息
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# Step 3: 更新并安装 Docker-CE
sudo yum makecache fast
#sudo yum -y install docker-ce
sudo yum install docker-ce docker-ce-cli containerd.io --nobest
# Step 4: 开启Docker服务
sudo systemctl start docker
sudo systemctl enable docker
#查看状态
sudo systemctl status docker
2、阿里云Kubernetest镜像的方法配置Kubernetes软件源,安装kubeclt此处选择CentOS(参考官方链接 https://developer.aliyun.com/mirror/kubernetes?spm=a2c6h.12873639.0.0.6c2362354SzVSX )
- Debian / Ubuntu
apt-get update && apt-get install -y apt-transport-https
curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF
apt-get update
apt-get install -y kubelet kubeadm kubectl
- CentOS / RHEL / Fedora
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
setenforce 0
#yum install -y kubelet kubeadm kubectl
#systemctl enable kubelet && systemctl start kubelet
#minikube安装,官方说明:只需要kubectl
sudo yum update
yum install -y kubectl
#ps: 由于官网未开放同步方式, 可能会有索引gpg检查失败的情况, 这时请用 yum install -y --nogpgcheck kubelet kubeadm kubectl 安装
3、阿里云minikube配置指南安装minikube
curl -Lo minikube https://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/releases/v1.14.2/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
为了访问海外的资源,阿里云提供了一系列基础设施,请按照如下参数进行配置。其中常见参数
--driver=***
从1.5.0版本开始,Minikube缺省使用本地最好的驱动来创建Kubernetes本地环境,测试过的版本docker
,kvm
--image-mirror-country cn
将缺省利用 registry.cn-hangzhou.aliyuncs.com/google_containers 作为安装Kubernetes的容器镜像仓库 (阿里云版本可选)--iso-url=***
利用阿里云的镜像地址下载相应的 .iso 文件 (阿里云版本可选)--registry-mirror=***
为了拉取Docker Hub镜像,需要为 Docker daemon 配置镜像加速,参考阿里云镜像服务--cpus=2
: 为minikube虚拟机分配CPU核数--memory=2048mb
: 为minikube虚拟机分配内存数--kubernetes-version=***
: minikube 虚拟机将使用的 kubernetes 版本
4、启动K8s集群(官方参考链接 https://minikube.sigs.k8s.io/docs/start/;也可以参考博客 https://blog.csdn.net/weixin_30809333/article/details/101340036)
minikube start
- 异常a,请执行下面脚本
minikube start --docker-env HTTPS_PROXY=${https://registry.docker-cn.com} --registry-mirror=https://registry-mirror.com --vm-driver=none
- 异常b ,请执行下面 sudo yum install conntrack
sudo yum install conntrack
minikube start --docker-env HTTPS_PROXY=${https://registry.docker-cn.com} --registry-mirror=https://registry-mirror.com --vm-driver=none
- 异常c,请执行下面
sudo mv /root/.kube /root/.minikube $HOME
sudo chown -R $USER $HOME/.kube $HOME/.minikube
#minikube start --docker-env HTTPS_PROXY=${https://registry.docker-cn.com} --registry-mirror=https://registry-mirror.com --vm-driver=none
#这是镜像加速地址 https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors?spm=a2c6h.12873639.0.0.ab202043HPVMuX&accounttraceid=9aeb6ddb011d4fb39a13157eed5e29afstpl,你可以得到 registy-mirror
minikube start --registry-mirror=https://ls16vb6g.mirror.aliyuncs.com --vm-driver=none
5、minikube安装的cluster信息查看(请参考官方文档 https://minikube.sigs.k8s.io/docs/start/)
6、Minikube基本操作
minikube start/stop/status/delete
7.Enable dashboard in minikube
查看minikube中所有addons
当你刚刚安装完minikube的时候查看所有的addons,
$ minikube addons list
|-----------------------------|----------|--------------|
| ADDON NAME | PROFILE | STATUS |
|-----------------------------|----------|--------------|
| ambassador | minikube | disabled |
| dashboard | minikube | disabled |
| default-storageclass | minikube | enabled ✅ |
| efk | minikube | disabled |
| freshpod | minikube | disabled |
| gvisor | minikube | disabled |
| helm-tiller | minikube | disabled |
| ingress | minikube | disabled |
| ingress-dns | minikube | disabled |
| istio | minikube | disabled |
| istio-provisioner | minikube | disabled |
| logviewer | minikube | disabled |
| metallb | minikube | disabled |
| metrics-server | minikube | disabled |
| nvidia-driver-installer | minikube | disabled |
| nvidia-gpu-device-plugin | minikube | disabled |
| olm | minikube | disabled |
| registry | minikube | disabled |
| registry-aliases | minikube | disabled |
| registry-creds | minikube | disabled |
| storage-provisioner | minikube | enabled ✅ |
| storage-provisioner-gluster | minikube | disabled |
|-----------------------------|----------|--------------|
- Enable an addon
$ minikube addons enable dashboard
- 可以再运行一下,
$ minikube addons list
- 检查一下结果。
8.安装minikube dashboard两种方法,分配一个固定的端口
1.在kubernetes文档上一般做法是运行命令
$ minikube dashboard
-
#address='192.168.0.97',为内网访IP kubectl proxy --port=8001 --address='192.168.0.97' --accept-hosts='^.*' &
-
红色部分127.0.0.1换成公网IP,集群分配的端口1-65535,均使用我们kubectl proxy代理的端口8001,就可以正常访问
2. minikube会把dashboard映射到一个本地端口上。每次这样做有点麻烦。下面我们为dashboard的pods创建一个service,我们以后可以通过这个service来访问dashboard,每次就可以使用minikube的ip address和这个service的端口来访问dashboard。
vim minikube-dashbord-svc.yaml
apiVersion: v1
kind: Service
metadata:
labels:
addonmanager.kubernetes.io/mode: Reconcile
k8s-app: kubernetes-dashboard
kubernetes.io/minikube-addons: dashboard
name: minikube-dashboard-uri
namespace: kubernetes-dashboard
spec:
ports:
- port: 80
protocol: TCP
targetPort: 9090
nodePort: 30080
selector:
k8s-app: kubernetes-dashboard
sessionAffinity: None
type: NodePort
kubectl apply -f minikube-dashbord-svc.yaml
通过NodePort:nodePort,就可以访问minikube dashboard
更多推荐
已为社区贡献9条内容
所有评论(0)