minicube安装

一、安装手册:

https://minikube.sigs.k8s.io/docs/start/

二、环境

  • linux Centos 7.6

三、安装

  1. 打开官网,选择和自己对应的系统和要下载的版本。

image

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
  1. 安装程序

    安装到自己需要位置,这里我安装到以下目录
    d:\Program Files\Kubernetes\Minikube

  2. 添加到系统变量

    Add the minikube.exe binary to your PATH.
    装启动程序加到系统变量

启动

注意:root用户启动会报错

# minikube start
minikube start --image-mirror-country=cn --cpus=2 --memory=2048mb --driver=docker \
--registry-mirror=https://qiyb9988.mirrors.aliyuncs.com \
--image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers  \
--iso-url=https://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/iso/minikube-v17.3.iso

报以下的错:

[root@haima opt]# minikube start --image-mirror-country=cn --cpus=2 --memory=2048mb --registry-mirror=https://qiyb9988.mirrors.aliyuncs.com --image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers --driver=docker --iso-url=https://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/iso/minikube-v17.3.iso
😄  minikube v1.30.1 on Centos 7.9.2009
✨  Using the docker driver based on user configuration
🛑  The "docker" driver should not be used with root privileges. If you wish to continue as root, use --force.
💡  If you are running minikube within a VM, consider using --driver=none:
📘    https://minikube.sigs.k8s.io/docs/reference/drivers/none/

❌  Exiting due to DRV_AS_ROOT: The "docker" driver should not be used with root privileges.

原因:服dorker命令不能与root用户启动

解决:

# root账号下执行 添加用户,并加到docker用户组中,使用新创建的用户启动
user add docker 添加docker用户
passwd docker 设置docker用户密码
groupadd docker 创建docker用户组
vim /etc/sudoers
添加
docker  ALL=(ALL)       ALL
systemctl stop docker 停止运行中的docker
su docker 切换用户



# 在docker用户下执行
systemctl start docker 启动运行中的docker
systemctl status docker 查看运行状态
sudo usermod -aG docker $USER && newgrp docker
# 执行启动命令
minikube start --image-mirror-country=cn --cpus=2 --memory=2048mb --driver=docker \
--registry-mirror=https://qiyb9988.mirrors.aliyuncs.com \
--image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers

root用户执行

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


yum install -y kubectl-1.22.4-0
yum install kubelet-1.18.0 kubeadm-1.18.0 kubectl-1.18.0 -y

cat <<EOF >/etc/sysconfig/kubelet
KUBELET_EXTRA_ARGS="--cgroup-driver=systemd"
KUBE_PROXY_MOOE="ipvs"
EOF

systemctl start kubelet
systemctl enable kubelet

docker 用户执行

[docker@haima root]$ kubectl get po -A
NAMESPACE     NAME                               READY   STATUS    RESTARTS      AGE
kube-system   coredns-567c556887-qfdtx           1/1     Running   0             20m
kube-system   etcd-minikube                      1/1     Running   0             20m
kube-system   kube-apiserver-minikube            1/1     Running   0             20m
kube-system   kube-controller-manager-minikube   1/1     Running   0             20m
kube-system   kube-proxy-khl9t                   1/1     Running   0             20m
kube-system   kube-scheduler-minikube            1/1     Running   0             20m
kube-system   storage-provisioner                1/1     Running   2 (20m ago)   20m
You have new mail in /var/spool/mail/root

至此已经安装成功

常用命令

minikube -h 
minikube status
minikube stop
minibube delete
minikube delete --all
minikube profile list # 查看集群状态

---
minikube node add # 添加节点 minikube node -h 查看帮助
minikube node list # 查看节点列表
minikube node delete  minikube-m02
minikube node start   minikube-m02
minikube node stop minikube-m02(节点名称)
k get no -o wide #使用这个可以看到节点状态

---
minikube addons -h
minikube addons list 查看插件列表

# 以后启动就不需要那么长的命令了
minikube start --image-mirror-country=cn \
--image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers

内存大小可以使用g 或者 m为单位
--memory='15g'   / --memory='2048m' 

minikube start --image-mirror-country=cn \
--image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers \
--cpus='2' --memory='15g' --nodes2 -p multinode-demo

# 如果要运行其他kubernetes版本(1.26.3  或者  1.2.5.8),使用以下命令 
minikube start --image-mirror-country='cn' --kubernetes-version=v1.23.0 --image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers

安装Dashboard

minikube dashboard --url --port=63373

不设置–port端口是随机的,每次启动可能会变化。

可以看到,启动了2个dashboard容器。

  • dashboard-metrics-scraper-5c6664855-khjmv
  • kubernetes-dashboard-55c4cbbc7c-8xhhm
[docker@haima root]$ kubectl get pod -A
NAMESPACE              NAME                                        READY   STATUS    RESTARTS      AGE
default                mynginx                                     1/1     Running   1 (30m ago)   2d
kube-system            coredns-567c556887-qfdtx                    1/1     Running   1 (30m ago)   5d23h
kube-system            etcd-minikube                               1/1     Running   1 (30m ago)   5d23h
kube-system            kube-apiserver-minikube                     1/1     Running   3 (18m ago)   5d23h
kube-system            kube-controller-manager-minikube            1/1     Running   3 (19m ago)   5d23h
kube-system            kube-proxy-khl9t                            1/1     Running   1             5d23h
kube-system            kube-scheduler-minikube                     1/1     Running   1 (30m ago)   5d23h
kube-system            storage-provisioner                         1/1     Running   6 (17m ago)   5d23h
kubernetes-dashboard   dashboard-metrics-scraper-5c6664855-khjmv   1/1     Running   0             5m18s
kubernetes-dashboard   kubernetes-dashboard-55c4cbbc7c-8xhhm       1/1     Running   0             5m18s

在浏览器访问(命令行退出后无法访问):
http://127.0.0.1:63373/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/

使用

docker pull quay.io/coreos/flannel:v0.10.0-amd64 


docker save -o kube-controllers.tar calico/kube-controllers:v3.21.5
docker save -o cni.tar calico/cni:v3.21.5
docker save -o pod2daemon-flexvol.tar calico/pod2daemon-flexvol:v3.21.5
docker save -o node.tar calico/node:v3.21.5

docker load < kube-controllers.tar
docker load < cni.tar
docker load < pod2daemon-flexvol.tar
docker load < node.tar

参考视频:

k8s测试环境搭建-minikube创建k8s集群
https://www.bilibili.com/video/BV1UM411N755/?spm_id_from=333.337.top_right_bar_window_history.content.click&vd_source=a68414cd60fe26e829ce1cdd4d75a9e6

2023云原生_k8s集群及常用组件安装 :https://zhuanlan.zhihu.com/p/619107675?

https://www.bilibili.com/video/BV1JP4y1P7MD/?spm_id_from=333.337.search-card.all.click&vd_source=a68414cd60fe26e829ce1cdd4d75a9e6
https://www.bilibili.com/video/BV1JP4y1P7MD/?spm_id_from=333.337.search-card.all.click&vd_source=a68414cd60fe26e829ce1cdd4d75a9e6
笔记:
https://www.bilibili.com/h5/note-app/view?cvid=14095637&pagefrom=comment