kubernetes 集群的搭建(最全)

1.安装docker(docker的版本与kubernetes 的版本兼容性需要注意)

# 配置docker仓库
wget -P /etc/yum.repos.d/ https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

# 安装docker-ce-18.06.0.ce-3.el7.x86_64
yum install -y docker-ce-18.06.0.ce-3.el7.x86_64

# yum安装docker普通版 
systemctl start docker.service 
#开启docker 
systemctl enable docker.service 

docker 存放目录的设置

例如存放到/home/docker下

ExecStart=/usr/bin/dockerd --graph /home/docker

2.安装kubernetes相关组件

配置kubernetes仓库

cat < /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-1.12.3
yum install -y kubeadm-1.12.3
yum install -y kubectl-1.12.3

3.获取相关的镜像

v1.12.3版本下载地址 联系邮箱:[email protected]

# 将多个镜像保存为文件
docker save -o k8s-1.12.3.tar k8s.gcr.io/kube-proxy:v1.12.3  k8s.gcr.io/kube-apiserver:v1.12.3 k8s.gcr.io/kube-controller-manager:v1.12.3 k8s.gcr.io/kube-scheduler:v1.12.3  k8s.gcr.io/etcd:3.2.24   k8s.gcr.io/coredns:1.2.2  quay.io/coreos/flannel:v0.10.0-amd64   k8s.gcr.io/pause:3.1  


# 将tar包load成镜像

docker load -i k8s-1.12.3.tar 

4.禁用节点上的swap

swapoff -a 
sysctl -p

vim /ets/fstab
#去除该文件中关于swap那行。

5.开启路由转发功能以及iptables的过滤策略。

vim /etc/sysctl.d/k8s.conf


net.bridge.bridge-nf-call-ip6tables = 1
#开启iptables中ipv6的过滤规则
net.bridge.bridge-nf-call-iptables = 1
#开启ipv4的过滤规则
net.ipv4.ip_forward = 1
#开启服务器的路由转发功能

#执行命令使修改生效。
modprobe br_netfilter
sysctl -p /etc/sysctl.d/k8s.conf

6.初始化master节点

#--kubernetes-version指明要下载的镜像版本
#--pod-network-cidr 指明网络的子网掩码,此处使用flannel模型的子网掩码
#--apiserver-advertise-address 指明与master结点绑定的ip

kubeadm init  --kubernetes-version=v1.12.3  --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=10.6.6.110

执行结果如下所示:

Your Kubernetes master has initialized successfully!

To start using your cluster, you need to run the following as a regular user:

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

You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
  https://kubernetes.io/docs/concepts/cluster-administration/addons/

You can now join any number of machines by running the following on each node
as root:
 
kubeadm join 10.6.6.192:6443 --token afbkdo.6335xh1w0lv7odbh --discovery-token-ca-cert-hash sha256:b9abe5a668609f0225c8bb3ecba3a70a0be370f90905fcce79a6d783bbd0aeef 

7.从节点的加入

kubeadm join 10.6.6.192:6443 --token afbkdo.6335xh1w0lv7odbh --discovery-token-ca-cert-hash sha256:b9abe5a668609f0225c8bb3ecba3a70a0be370f90905fcce79a6d783bbd0aeef 

8.配置主节点是否参与调度

#master运行pod
kubectl taint nodes master.k8s node-role.kubernetes.io/master-

#master不运行pod
kubectl taint nodes master.k8s node-role.kubernetes.io/master=:NoSchedule

9.开启非安全端口访问

修改/etc/kubernetes/manifests/kube-apiserver.yaml


- --secure-port=6443
- --insecure-bind-address=0.0.0.0
- --insecure-port=8080


10.配置证书续期

TLS bootstrapping 时的证书实际是由 kube-controller-manager 组件来签署的,也就是说证书有效期是 kube-controller-manager 组件控制的;kube-controller-manager 组件提供了一个 --experimental-cluster-signing-duration 参数来设置签署的证书有效时间;默认为 8760h0m0s,将其改为 87600h0m0s 即 10 年后再进行 TLS bootstrapping 签署证书即可。

同样是一个软连接文件,当 kubelet 配置了 --feature-gates=RotateKubeletServerCertificate=true 选项后,会在证书总有效期的 70%~90% 的时间内发起续期请求,请求被批准后会生成一个 kubelet-server-时间戳.pem;kubelet-server-current.pem 文件则始终软连接到最新的真实证书文件,该文件将会一直被用于 kubelet 10250 api 端口鉴权

- --kubeconfig=/etc/kubernetes/controller-manager.conf
- --experimental-cluster-signing-duration=87600h0m0s
- --feature-gates=RotateKubeletServerCertificate=true

谢谢你的打赏支持

kubernetes 集群的搭建(最全)_第1张图片

你可能感兴趣的:(k8s,kubernetes)