centos安装minikube

1 篇文章 0 订阅
1 篇文章 0 订阅


前言

minikube的安装过程很简单,不过对于初次安装者还是有很多需要注意的事情。下面就讲讲安装过程和其中的注意事项。


一、minikube是什么?

minikube 是本地 Kubernetes,优点是:快速启动,消耗机器资源较少,非常适合新手体验与开发。

二、安装步骤与注意事项

1. 安装前准备

1.1 必须安装docker

1.2 非必需安装 kubectl

  • 启动minikube时会自动安装kubectl,只不过是用容器的方式安装的,需要如下使用命令: minikube kubectl -- get po -A
  • 也可以自行安装kubectl在本机,安装完成后使用命令如下: kubectl -- get po -A
  • 自行安装kubectl的教程:https://kubernetes.io/zh-cn/docs/tasks/tools/install-kubectl-linux/

1.3 不需要安装 kubeadm 与 kubelet

  • 启动minikube时会自动用容器安装 kubeadm 与 kubelet,即使你在本机安装了kubeadm 与 kubelet也不会使用

1.4 创建一个具有root权限的用户

  • 如果已经有了就不必要创建,下面安装minikube请在该账户下操作。
  • 需要将该用户添加进入docker用户组
    1. 添加该用户至docker用户组:sudo gpasswd -a $USER docker
    2. 更新docker用户组: newgrp docker
  • 创建用户的参考链接:https://blog.csdn.net/weixin_44462664/article/details/109684675

2.安装与启动

请在非root用户下操作,以避免报错。

2.1 安装

  • 参考链接:https://minikube.sigs.k8s.io/docs/start/
  • 按下图选择后会出现两条命令,依次执行安装即可:
    1. curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
    2. sudo install minikube-linux-amd64 /usr/local/bin/minikube
      在这里插入图片描述
  • 命令执行截图:
    在这里插入图片描述

2.2 启动集群

  • 启动命令: minikube start --image-mirror-country='cn' --kubernetes-version=v1.23.8
  • 命令执行截图:
    在这里插入图片描述
  • 启动完成
  • 启动参数参考:
  1. –driver=*** 从1.5.0版本开始,Minikube缺省使用系统优选的驱动来创建Kubernetes本地环境,比如您已经安装过Docker环境,minikube 将使用 docker 驱动
  2. –cpus=2: 为minikube虚拟机分配CPU核数
  3. –memory=2048mb: 为minikube虚拟机分配内存数
  4. –registry-mirror=*** 为了提升拉取Docker Hub镜像的稳定性,可以为 Docker daemon 配置镜像加速,参考阿里云镜像服务
  5. –kubernetes-version=***: minikube 虚拟机将使用的 kubernetes 版本,建议选择v1.23.8,不然会报错
  6. –image-mirror-country=***:minikube使用的镜像库所在国家,建议选择cn使用国内库,不然会连不上国外的网络,导致无法下载镜像

2.3 验证

  • 验证:如果你自行安装了kubectl请使用 kubectl -- get po -A,若没有则使用 minikube kubectl -- get po -A
  • 命令执行截图:
    在这里插入图片描述

三、启动集群报错与处理

1. kubeadm init失败 与 kubelet 服务未启动

1.1 报错信息

💢  initialization failed, will try again: wait: /bin/bash -c "sudo env PATH="/var/lib/minikube/binaries/v1.25.0:$PATH" kubeadm init --config /var/tmp/minikube/kubeadm.yaml  --ignore-preflight-errors=DirAvailable--etc-kubernetes-manifests,DirAvailable--var-lib-minikube,DirAvailable--var-lib-minikube-etcd,FileAvailable--etc-kubernetes-manifests-kube-scheduler.yaml,FileAvailable--etc-kubernetes-manifests-kube-apiserver.yaml,FileAvailable--etc-kubernetes-manifests-kube-controller-manager.yaml,FileAvailable--etc-kubernetes-manifests-etcd.yaml,Port-10250,Swap,Mem,SystemVerification,FileContent--proc-sys-net-bridge-bridge-nf-call-iptables": Process exited with status 1
stdout:
[init] Using Kubernetes version: v1.25.0
[preflight] Running pre-flight checks
[preflight] Pulling images required for setting up a Kubernetes cluster
[preflight] This might take a minute or two, depending on the speed of your internet connection
[preflight] You can also perform this action in beforehand using 'kubeadm config images pull'
[certs] Using certificateDir folder "/var/lib/minikube/certs"
[certs] Using existing ca certificate authority
[certs] Using existing apiserver certificate and key on disk
[certs] Generating "apiserver-kubelet-client" certificate and key
[certs] Generating "front-proxy-ca" certificate and key
[certs] Generating "front-proxy-client" certificate and key
[certs] Generating "etcd/ca" certificate and key
[certs] Generating "etcd/server" certificate and key
[certs] etcd/server serving cert is signed for DNS names [localhost minikube] and IPs [192.168.49.2 127.0.0.1 ::1]
[certs] Generating "etcd/peer" certificate and key
[certs] etcd/peer serving cert is signed for DNS names [localhost minikube] and IPs [192.168.49.2 127.0.0.1 ::1]
[certs] Generating "etcd/healthcheck-client" certificate and key
[certs] Generating "apiserver-etcd-client" certificate and key
[certs] Generating "sa" key and public key
[kubeconfig] Using kubeconfig folder "/etc/kubernetes"
[kubeconfig] Writing "admin.conf" kubeconfig file
[kubeconfig] Writing "kubelet.conf" kubeconfig file
[kubeconfig] Writing "controller-manager.conf" kubeconfig file
[kubeconfig] Writing "scheduler.conf" kubeconfig file
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Starting the kubelet
[control-plane] Using manifest folder "/etc/kubernetes/manifests"
[control-plane] Creating static Pod manifest for "kube-apiserver"
[control-plane] Creating static Pod manifest for "kube-controller-manager"
[control-plane] Creating static Pod manifest for "kube-scheduler"
[etcd] Creating static Pod manifest for local etcd in "/etc/kubernetes/manifests"
[wait-control-plane] Waiting for the kubelet to boot up the control plane as static Pods from directory "/etc/kubernetes/manifests". This can take up to 4m0s
[kubelet-check] Initial timeout of 40s passed.

Unfortunately, an error has occurred:
	timed out waiting for the condition

This error is likely caused by:
	- The kubelet is not running
	- The kubelet is unhealthy due to a misconfiguration of the node in some way (required cgroups disabled)

If you are on a systemd-powered system, you can try to troubleshoot the error with the following commands:
	- 'systemctl status kubelet'
	- 'journalctl -xeu kubelet'

Additionally, a control plane component may have crashed or exited when started by the container runtime.
To troubleshoot, list all containers using your preferred container runtimes CLI.
Here is one example how you may list all running Kubernetes containers by using crictl:
	- 'crictl --runtime-endpoint unix:///var/run/cri-dockerd.sock ps -a | grep kube | grep -v pause'
	Once you have found the failing container, you can inspect its logs with:
	- 'crictl --runtime-endpoint unix:///var/run/cri-dockerd.sock logs CONTAINERID'

stderr:
W0921 08:01:08.970490    1512 initconfiguration.go:119] Usage of CRI endpoints without URL scheme is deprecated and can cause kubelet errors in the future. Automatically prepending scheme "unix" to the "criSocket" with value "/var/run/cri-dockerd.sock". Please update your configuration!
	[WARNING FileContent--proc-sys-net-bridge-bridge-nf-call-iptables]: /proc/sys/net/bridge/bridge-nf-call-iptables does not exist
	[WARNING Service-Kubelet]: kubelet service is not enabled, please run 'systemctl enable kubelet.service'
error execution phase wait-control-plane: couldn't initialize a Kubernetes cluster
To see the stack trace of this error execute with --v=5 or higher

    ▪ Generating certificates and keys ...
    ▪ Booting up control plane ...

💣  开启 cluster 时出错: wait: /bin/bash -c "sudo env PATH="/var/lib/minikube/binaries/v1.25.0:$PATH" kubeadm init --config /var/tmp/minikube/kubeadm.yaml  --ignore-preflight-errors=DirAvailable--etc-kubernetes-manifests,DirAvailable--var-lib-minikube,DirAvailable--var-lib-minikube-etcd,FileAvailable--etc-kubernetes-manifests-kube-scheduler.yaml,FileAvailable--etc-kubernetes-manifests-kube-apiserver.yaml,FileAvailable--etc-kubernetes-manifests-kube-controller-manager.yaml,FileAvailable--etc-kubernetes-manifests-etcd.yaml,Port-10250,Swap,Mem,SystemVerification,FileContent--proc-sys-net-bridge-bridge-nf-call-iptables": Process exited with status 1

1.2 可能原因

  • minikube start 的命令里未使用 --image-mirror-country=‘cn’,导致下载启动镜像不成功。
  • minikube start 的命令里未使用 --kubernetes-version 指定版本,kubernetes最新版兼容性有问题,所以得使用低版本的kubernetes,推荐使用–kubernetes-version=v1.23.8

1.3 解决方案

请使用下列命令启动: minikube start --image-mirror-country='cn' --kubernetes-version=v1.23.8


总结

安装启动minikube还是挺简单的,不过对于新手来说,有可能没有准备好环境与命令,就直接执行官方的命令,这样一定会报错的。本文基于自己的安装经验写成,希望能使大家少走一些弯路。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值