硬件需求

2cpu 2g 内存

安装容器运行时 docker

http://blog.19910813.cn//archives/docker-install-production

配置镜像加速器

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://2s9yrmio.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

安装k8s

1,修改机器名

vi /etc/hostname

2,修改为manager node1 node2

安装 kubelet kubeadm kubectl
sudo apt-get update && sudo apt-get install -y apt-transport-https curl

添加gpg
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
上面的命令因为外网不通的问题,需要在本地shadowsocks下载好,再上传到服务器 cat 文件 再添加
添加源
cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb 阿里云开源镜像站资源目录 kubernetes-xenial main
EOF
sudo apt-get update

(最好指定kubelet kubeadm kubectl的版本 否则k8s后面需要启动拉取的镜像可能需要更新)

sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl

配置kubectl 配置文件 /etc/default/kubelet
KUBELET_EXTRA_ARGS=--cgroup-driver=systemd

重新启动 kubelet:
systemctl daemon-reload
systemctl restart kubelet

modprobe br_netfilter
echo 1 > /proc/sys/net/bridge/bridge-nf-call-iptables

echo 1 > /proc/sys/net/ipv4/ip_forward

获取启动k8s所需的镜像:

kubeadm config images list

获取启动k8s所需的镜像:

kubeadm config images list

k8s.gcr.io/kube-apiserver:v1.18.6
k8s.gcr.io/kube-controller-manager:v1.18.6
k8s.gcr.io/kube-scheduler:v1.18.6
k8s.gcr.io/kube-proxy:v1.18.6
k8s.gcr.io/pause:3.2
k8s.gcr.io/etcd:3.4.3-0
k8s.gcr.io/coredns:1.6.7

拉取k8s所需的镜像(manager和node节点都需要拉取):
docker pull registry.cn-hangzhou.aliyuncs.com/fushiyong/kube-apiserver:v1.18.6
docker pull registry.cn-hangzhou.aliyuncs.com/fushiyong/kube-controller-manager:v1.18.6
docker pull registry.cn-hangzhou.aliyuncs.com/fushiyong/kube-scheduler:v1.18.6
docker pull registry.cn-hangzhou.aliyuncs.com/fushiyong/kube-proxy:v1.18.6
docker pull registry.cn-hangzhou.aliyuncs.com/fushiyong/pause:3.2
docker pull registry.cn-hangzhou.aliyuncs.com/fushiyong/etcd:3.4.3-0
docker pull registry.cn-hangzhou.aliyuncs.com/fushiyong/coredns:1.6.7

docker tag registry.cn-hangzhou.aliyuncs.com/fushiyong/kube-apiserver:v1.18.6 k8s.gcr.io/kube-apiserver:v1.18.6
docker tag registry.cn-hangzhou.aliyuncs.com/fushiyong/kube-controller-manager:v1.18.6 k8s.gcr.io/kube-controller-manager:v1.18.6
docker tag registry.cn-hangzhou.aliyuncs.com/fushiyong/kube-scheduler:v1.18.6 k8s.gcr.io/kube-scheduler:v1.18.6
docker tag registry.cn-hangzhou.aliyuncs.com/fushiyong/kube-proxy:v1.18.6 k8s.gcr.io/kube-proxy:v1.18.6
docker tag registry.cn-hangzhou.aliyuncs.com/fushiyong/pause:3.2 k8s.gcr.io/pause:3.2
docker tag registry.cn-hangzhou.aliyuncs.com/fushiyong/etcd:3.4.3-0 k8s.gcr.io/etcd:3.4.3-0
docker tag registry.cn-hangzhou.aliyuncs.com/fushiyong/coredns:1.6.7 k8s.gcr.io/coredns:1.6.7

kubeadm init

开放 apiserver端口 ,否则node节点无法连接。
iptables -I INPUT -p tcp --dport 6443 -j ACCEPT

如果初始化失败,需要重置kubeadm,然后再次初始化
kubeadm reset

设置kubectl连接配置文件

设置Master节点Kubelet客户端连接配置文件
mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config

Node节点客户端连接配置文件,否则无法执行kubectl

mkdir -p $HOME/.kube
cp -i /etc/kubernetes/kubelet.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐