centos安装kubectl和minikube工具

简介: centos安装kubectl和minikube工具

kubectl和minikube是部署kubernetes集群的2个重要工具,本文主要介绍如何安装这2个工具。

安装环境:centos7虚拟机

一、安装kubectl

kubectl是k8s命令行工具,用在k8s集群中,可以部署应用、查看和管理集群资源。使用kubectl版本不能跟集群版本差别太大,最好使用最新版本的kubectl。

1.下载安装包,如下2个命令,第一个下载最新版本,第二个下载指定版本

curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.17.0/bin/linux/amd64/kubectl

2.kubectl不能执行,增加执行权限

微信图片_20221212095627.png


chmod +x kubectl

微信图片_20221212095703.png

3.把安装包移动到path目录


mv ./kubectl /usr/local/bin/kubectl

4.查看版本是不是最新版


kubectl version --client

微信图片_20221212095750.png

二、安装docker hypervisor

因为本地安装环境使用的就是虚拟机,所以不再进行虚拟了。

这里推荐安装VirtualBox

使用yum安装,安装方法:

创建/etc/yum.repos.d/virtualbox.repo文件,内容如下:


[virtualbox]
name=Oracle Linux / RHEL / CentOS-$releasever / $basearch - VirtualBox
baseurl=http://download.virtualbox.org/virtualbox/rpm/el/$releasever/$basearch
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://www.virtualbox.org/download/oracle_vbox.asc

之后执行


yum install VirtualBox-6.0

之后一直选择“y”就完成了微信图片_20221212095913.jpg

三、安装Minikube

1.Minikube这个工具支持在虚拟机上运行一套单节点的k8s集群

开始安装前,先查看本地机器是否支持虚拟化,有输出就支持


grep -E --color 'vmx|svm' /proc/cpuinfo

我使用的机器是windows上使用vmware隔离出的一个虚拟机,如第二节中所示就不再安装虚拟机工具了。

虚拟机执行上面命令没有输出,可以采用下面的方法支持虚拟化。

关掉虚机,选择如下图的选型后重新开启虚拟机

微信图片_20221212100006.jpg

2.安装minikube有3种方法,package包安装、二进制文件安装和使用homebrew安装,这里我采用二进制包方式安装,执行如下命令下载

    curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/min

    微信图片_20221212100034.png

    把minikube可执行文件添加到path

    sudo mkdir -p /usr/local/bin/
    sudo install minikube /usr/local/bin/

    3.启动minikube

    minikube start --vm-driver=virtualbox

    报错如下:

    微信图片_20221212100143.png

    看意思就是虚拟机里面运行的话,后面的参数值等于none

      minikube start --vm-driver=none

      再次报错

      微信图片_20221212100211.png

      关掉虚拟机,重新设置CPU数量

      微信图片_20221212100238.jpg

      4.再次启动minikube

        minikube start --vm-driver=none

        微信图片_20221212100315.jpg

        更换阿里云镜像,重新执行启动命令


        minikube start --image-repository='registry.cn-hangzhou.aliyuncs.com/google_

        这个过程会下载kubectl、kubelet、kubeadm这3个镜像,大概400M,所以比较慢,耐心等待。下载后自动启动

        微信图片_20221212100356.png

        再次报错,从报错中看出,apiserver启动失败了,用命令可以确认下:minikube status

        微信图片_20221212100424.png

        查阅网上资料,有一些是swap没有关闭。swapoff -a关闭swap,继续执行minikube启动命令,依然失败。 执行minikube   delete,再次执行启动命令,这次出现了很多错误日志:

        X 开启 cluster 时出错: init failed. output: "-- stdout --\n[init] Using Kubernetes version: v1.17.3\n[preflight] Running pre-flight checks\n[preflight] Pulling images required for setting up a Kubernetes cluster\n[preflight] This might take a minute or two, depending on the speed of your internet connection\n[preflight] You can also perform this action in beforehand using 'kubeadm config images pull'\n[kubelet-start] Writing kubelet environment file with flags to file \"/var/lib/kubelet/kubeadm-flags.env\"\n[kubelet-start] Writing kubelet configuration to file \"/var/lib/kubelet/config.yaml\"\n[kubelet-start] Starting the kubelet\n[certs] Using certificateDir folder \"/var/lib/minikube/certs\"\n[certs] Using existing ca certificate authority\n[certs] Using existing apiserver certificate and key on disk\n[certs] Generating \"apiserver-kubelet-client\" certificate and key\n[certs] Generating \"front-proxy-ca\" certificate and key\n[certs] Generating \"front-proxy-client\" certificate and key\n[certs] Generating \"etcd/ca\" certificate and key\n[certs] Generating \"etcd/server\" certificate and key\n[certs] etcd/server serving cert is signed for DNS names [localhost.localdomain localhost] and IPs [192.168.59.128 127.0.0.1 ::1]\n[certs] Generating \"etcd/peer\" certificate and key\n[certs] etcd/peer serving cert is signed for DNS names [localhost.localdomain localhost] and IPs [192.168.59.128 127.0.0.1 ::1]\n[certs] Generating \"etcd/healthcheck-client\" certificate and key\n[certs] Generating \"apiserver-etcd-client\" certificate and key\n[certs] Generating \"sa\" key and public key\n[kubeconfig] Using kubeconfig folder \"/etc/kubernetes\"\n[kubeconfig] Writing \"admin.conf\" kubeconfig file\n[kubeconfig] Writing \"kubelet.conf\" kubeconfig file\n[kubeconfig] Writing \"controller-manager.conf\" kubeconfig file\n[kubeconfig] Writing \"scheduler.conf\" kubeconfig file\n[control-plane] Using manifest folder \"/etc/kubernetes/manifests\"\n[control-plane] Creating static Pod manifest for \"kube-apiserver\"\n[control-plane] Creating static Pod manifest for \"kube-controller-manager\"\n[control-plane] Creating static Pod manifest for \"kube-scheduler\"\n[etcd] Creating static Pod manifest for local etcd in \"/etc/kubernetes/manifests\"\n[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\n[kubelet-check] Initial timeout of 40s passed.\n[kubelet-check] It seems like the kubelet isn't running or healthy.\n[kubelet-check] The HTTP call equal to 'curl -sSL http://localhost:10248/healthz' failed with error: Get http://localhost:10248/healthz: dial tcp [::1]:10248: connect: connection refused.\n\nUnfortunately, an error has occurred:\n\ttimed out waiting for the condition\n\nThis error is likely caused by:\n\t- The kubelet is not running\n\t- The kubelet is unhealthy due to a misconfiguration of the node in some way (required cgroups disabled)\n\nIf you are on a systemd-powered system, you can try to troubleshoot the error with the following commands:\n\t- 'systemctl status kubelet'\n\t- 'journalctl -xeu kubelet'\n\nAdditionally, a control plane component may have crashed or exited when started by the container runtime.\nTo troubleshoot, list all containers using your preferred container runtimes CLI, e.g. docker.\nHere is one example how you may list all Kubernetes containers running in docker:\n\t- 'docker ps -a | grep kube | grep -v pause'\n\tOnce you have found the failing container, you can inspect its logs with:\n\t- 'docker logs CONTAINERID'\n\n-- /stdout --\n** stderr ** \nW0227 14:11:35.372509   50864 validation.go:28] Cannot validate kube-proxy config - no validator is available\nW0227 14:11:35.372637   50864 validation.go:28] Cannot validate kubelet config - no validator is available\n\t[WARNING Firewalld]: firewalld is active, please ensure ports [8443 10250] are open or your cluster may not function correctly\n\t[WARNING FileExisting-socat]: socat not found in system path\nW0227 14:11:42.309644   50864 manifests.go:214] the default kube-apiserver authorization-mode is \"Node,RBAC\"; using \"Node,RBAC\"\nW0227 14:11:42.313619   50864 manifests.go:214] the default kube-apiserver authorization-mode is \"Node,RBAC\"; using \"Node,RBAC\"\nerror execution phase wait-control-plane: couldn't initialize a Kubernetes cluster\nTo see the stack trace of this error execute with --v=5 or higher\n\n** /stderr **": /bin/bash -c "sudo env PATH=/var/lib/minikube/binaries/v1.17.3:$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,SystemVerification": exit status 1
        stdout:
        [init] Using Kubernetes version: v1.17.3
        [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'
        [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
        [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.localdomain localhost] and IPs [192.168.59.128 127.0.0.1 ::1]
        [certs] Generating "etcd/peer" certificate and key
        [certs] etcd/peer serving cert is signed for DNS names [localhost.localdomain localhost] and IPs [192.168.59.128 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
        [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.
        [kubelet-check] It seems like the kubelet isn't running or healthy.
        [kubelet-check] The HTTP call equal to 'curl -sSL http://localhost:10248/healthz' failed with error: Get http://localhost:10248/healthz: dial tcp [::1]:10248: connect: connection refused.
        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, e.g. docker.
        Here is one example how you may list all Kubernetes containers running in docker:
                - 'docker ps -a | grep kube | grep -v pause'
                Once you have found the failing container, you can inspect its logs with:
                - 'docker logs CONTAINERID'
        stderr:
        W0227 14:11:35.372509   50864 validation.go:28] Cannot validate kube-proxy config - no validator is available
        W0227 14:11:35.372637   50864 validation.go:28] Cannot validate kubelet config - no validator is available
                [WARNING Firewalld]: firewalld is active, please ensure ports [8443 10250] are open or your cluster may not function correctly
                [WARNING FileExisting-socat]: socat not found in system path
        W0227 14:11:42.309644   50864 manifests.go:214] the default kube-apiserver authorization-mode is "Node,RBAC"; using "Node,RBAC"
        W0227 14:11:42.313619   50864 manifests.go:214] the default kube-apiserver authorization-mode is "Node,RBAC"; using "Node,RBAC"
        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
        * 
        * 由于出错 minikube 正在退出。如果以上信息没有帮助,请提交问题反馈:
          - https://github.com/kubernetes/minikube/issues/new/choose

        信息量很大,但是很难一下子找出原因。结合当前现状:apiserver启动失败,看错误日志后面一句:

          error execution phase wait-control-plane: couldn't initialize a Kubernetes  cluster

          网上搜这句,有很多文章,有的建议关闭SELINUX,关闭SELINUX,重启,果然生效,重启后apiserver直接启动成功

          微信图片_20221212100548.png

          参考资料:


          https://kubernetes.io/docs/tasks/tools/install-minikube/

          https://www.itzgeek.com/how-tos/linux/centos-how-tos/install-virtualbox-4-3-on-centos-7-rhel-7.html

          https://kubernetes.io/docs/tasks/tools/install-kubectl/#download-as-part-of-the-google-cloud-sdk

          https://forum.level1techs.com/t/kubeadm-for-kubernetes-chicken-and-egg-problem-during-setup-what-am-i-doing-wrong/129086/4


          相关实践学习
          深入解析Docker容器化技术
          Docker是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的Linux机器上,也可以实现虚拟化,容器是完全使用沙箱机制,相互之间不会有任何接口。Docker是世界领先的软件容器平台。开发人员利用Docker可以消除协作编码时“在我的机器上可正常工作”的问题。运维人员利用Docker可以在隔离容器中并行运行和管理应用,获得更好的计算密度。企业利用Docker可以构建敏捷的软件交付管道,以更快的速度、更高的安全性和可靠的信誉为Linux和Windows Server应用发布新功能。 在本套课程中,我们将全面的讲解Docker技术栈,从环境安装到容器、镜像操作以及生产环境如何部署开发的微服务应用。本课程由黑马程序员提供。     相关的阿里云产品:容器服务 ACK 容器服务 Kubernetes 版(简称 ACK)提供高性能可伸缩的容器应用管理能力,支持企业级容器化应用的全生命周期管理。整合阿里云虚拟化、存储、网络和安全能力,打造云端最佳容器化应用运行环境。 了解产品详情: https://www.aliyun.com/product/kubernetes
          相关文章
          |
          6月前
          |
          存储 Ubuntu Linux
          VMware-安装CentOS系统教程及安装包
          虚拟机相当于是一个独立于你电脑的环境,在这个环境上面,你可以安装Linux、Windows、Ubuntu等各个类型各个版本的系统,在这个系统里面你不用担心有病读等,不用担心文件误删导致系统崩溃。 虚拟机也和正常的电脑系统是一样的,也可以开关机,不用的时候,你关机就可以了,也不会占用你的系统资源,使用起来还是比较方便 这里也有已经做好的CentOS 7系统,下载下来解压后直接用VMware打开就可以使用
          1219 69
          |
          5月前
          |
          存储 分布式计算 Linux
          安装篇--CentOS 7 虚拟机安装
          VMware 装 CentOS 7 不知道从哪下手?这篇超详细图文教程手把手教你在 VMware Workstation 中完成 CentOS 7 桌面系统的完整安装流程。从 ISO 镜像下载、虚拟机配置,到安装图形界面、设置用户密码,每一步都有截图讲解,适合零基础新手快速上手。装好之后无论你是要搭 Hadoop 集群,还是练 Linux ,这个环境都够你折腾一整天!
          2185 3
          |
          6月前
          |
          Ubuntu Linux 索引
          Centos 7、Debian及Ubuntu系统中安装和验证tree命令的指南。
          通过上述步骤,我们可以在CentOS 7、Debian和Ubuntu系统中安装并验证 `tree`命令。在命令行界面中执行安装命令,然后通过版本检查确认安装成功。这保证了在多个平台上 `tree`命令的一致性和可用性,使得用户无论在哪种Linux发行版上都能使用此工具浏览目录结构。
          553 78
          |
          5月前
          |
          安全 关系型数据库 MySQL
          CentOS 7 yum 安装 MySQL教程
          在CentOS 7上安装MySQL 8,其实流程很清晰。首先通过官方Yum仓库来安装服务,然后启动并设为开机自启。最重要的环节是首次安全设置:需要先从日志里找到临时密码来登录,再修改成你自己的密码,并为远程连接创建用户和授权。最后,也别忘了在服务器防火墙上放行3306端口,这样远程才能连上。
          1027 16
          |
          6月前
          |
          存储 关系型数据库 MySQL
          在CentOS 8.x上安装Percona Xtrabackup工具备份MySQL数据步骤。
          以上就是在CentOS8.x上通过Perconaxtabbackup工具对Mysql进行高效率、高可靠性、无锁定影响地实现在线快速全量及增加式数据库资料保存与恢复流程。通过以上流程可以有效地将Mysql相关资料按需求完成定期或不定期地保存与灾难恢复需求。
          521 10
          |
          6月前
          |
          运维 网络协议 Linux
          CentOS下Bind服务的安装与故障排查
          通过以上的步骤,您应该能够在CentOS系统上安装并配置BIND DNS服务,并进行基本的故障排查。
          569 0
          |
          6月前
          |
          存储 Ubuntu Linux
          安卓手机免root安装各种Linux系统:Ubuntu, Centos,Kali等
          此外还可以安装Slackware、Archstrike等系统,还可以通过github查找方法安装更多有趣的东西。 昨日小编就是通过Termux安装的Kali Linux工具包。
          |
          7月前
          |
          Linux 网络安全 Apache
          针对在Centos/Linux安装Apache过程中出现的常见问题集锦
          以上每个问题的解决方案应深入分析错误日志、系统消息和各种配置文件,以找到根本原因并加以解决。务必保持系统和Apache软件包更新到最新版本,以修复已知的bugs和安全漏洞。安装和管理Web服务器是一项需要细致关注和不断学习的任务。随着技术的发展,推荐定期查看官方文档和社区论坛,以保持知识的更新。
          306 80
          |
          8月前
          |
          机器人 Linux
          CentOS 7系统中安装特定版本CMake 3.21.2的方法。
          到这里,过程已经全部完成。如果你跟随上面的步骤来,那么你现在已经拥有了一个全新的CMake版本在你的CentOS 7系统上了。这个过程就像是你通过一系列仪式,唤醒了一个沉睡已久的古老机器人,它现在完全按照你的意愿来帮你构建和编译软件了。
          623 18