系统环境
- Centos 7
- 关闭swap
- 尽量使用国内源
Kubernetes组件
Master节点
- kube-apiserver: 暴露api,集群操作入口
- etcd: 存储
- kueb-scheduler: Pod调度,为Pod分配运行节点
- kube-controller-manager: 管理各种控制器,如节点,pod,replica等
Node节点
- kbuelet: 管理Pod中的容器
- kube-proxy: 访问控制和流量转发
- container-runtime: 容器运行时环境
插件
- DNS
- 网络
- WEB UI
- 等等
安装 Docker
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sudo yum makecache fast
sudo yum -y install docker-ce
sudo systemctl enable --now docker
# 修改docker cgroupdriver 为systemd
echo '{ "exec-opts": ["native.cgroupdriver=systemd"]}' > /etc/docker/daemon.json
systemctl restart docker
# 安装指定版本的Docker-CE:
# Step 1: 查找Docker-CE的版本:
# yum list docker-ce.x86_64 --showduplicates | sort -r
# sudo yum -y install docker-ce-[VERSION]
安装 kubelet kubeadm kubectl
cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
sysctl --system
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
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 kubelet kubeadm kubectl
systemctl enable kubelet && systemctl start kubelet
使用kubeadm初始化集群
kubeadm init --pod-network-cidr=10.244.0.0/16 \
--apiserver-advertise-address=192.168.56.101 \
--image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers
kubeadm join --apiserver-advertise-address=192.168.56.102 192.168.56.101:6443
--token jl21vj.nluztkcmh6onsks8
--discovery-token-ca-cert-hash \
sha256:90a57395a16159748389a302dceb2c8217bed1900aba1b0497015ef8df325c17
网络插件
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
网络代理
如果安装过程中需要配置代理,可通过环境变量配置。systemd管理的服务需要service.utils文件中配置
export http_proxy="http://192.168.56.1:1188"
export https_proxy="http://192.168.56.1:1188"
export no_proxy="127.0.0.1,192.168.56.101,192.168.56.102,localhost"