安装kubernetes的几种方法

安装kubernetes的几种方法

1 环境

如果没有物理机或者云主机的话,可以使用VirtualBox或者VMware安装的虚拟机器操作,建议配置如下

(1)操作系统:centos 7,64位

(2)内存:建议内存给2G以上

(3)cpu:建议给2核以上

2 yum安装

2.1 步骤

(1)关闭防火墙

systemctl stop firewalld
systemctl disable firewalld

(2)安装etcd和kubernetes软件

yum -y install etcd kubernetes

ps: docker 会被自动安装,无需再次安装docker

(3)修改docker以及kubernetes配置

docker配置文件/etc/sysconfig/docker, OPTIONS 参数改为一下内容

OPTIONS='--selinux-enabled=false --log-driver=journald --signature-verification=false --insecure-registry gcr.io'

kubernetes apiserver配置文件/etc/kubernetes/apiserver, 将KUBE_ADMISSION_CONTROL参数中的 ServiceAccount 去掉

Ps:养成好习惯,改之前先将原文件备份

(4)配置国内网络加速

创建/etc/docker/daemon.json文件,并添加如下配置

{
  "registry-mirrors": [
    "https://ung2thfc.mirror.aliyuncs.com",
    "https://registry.docker-cn.com",
    "http://hub-mirror.c.163.com",
    "https://docker.mirrors.ustc.edu.cn"
}

(5)启动服务

systemctl start etcd
systemctl start docker
systemctl start kube-apiserver
systemctl start kube-controller-manager
systemctl start kube-scheduler
systemctl start kubelet
systemctl start kube-proxy

2.2 报错处理

由于环境不一样,可能会遇到以下问题

(1)拉取pod-infrastructure镜像认证失败

现象:

Sep 17 04:15:02 init dockerd-current: time="2022-09-17T04:15:02.889226258-04:00" level=error msg="Handler for GET /v1.26/images/registry.access.redhat.com/rhel7/pod-infrastructure:latest/json returned error: No such image: registry.access.redhat.com/rhel7/pod-infrastructure:latest"
Sep 17 04:15:02 init kubelet: E0917 04:15:02.890596    4281 docker_manager.go:2159] Failed to create pod infra container: ImagePullBackOff; Skipping pod "mysql-t9268_default(97d68d91-365f-11ed-8c24-000c290ac12a)": Back-off pulling image "registry.access.redhat.com/rhel7/pod-infrastructure:latest"