192.168.1.252 k8s-node02
192.168.1.73 k8s-node01
192.168.1.101 k8s-master
a) 设定时间同步
b) 本地hosts文件DNS解析
c) 关闭iptables或者firewwalld并确保开启不会自启动
d) 关闭selinux 禁用swap设备
e) 如果使用ipvs的proxy模型 各节点需要载入ipvs的各模块
[root@k8s-node02 ~]# systemctl start chronyd
[root@k8s-node02 ~]# systemctl enable chronyd
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
vm.swappiness = 0
modprobe br_netfilter
sysctl -p
A) ipvs目录:/usr/lib/modules/$(uname -r)/kernel/net/netfilter/ipvs
装入ip_vs模块:
[root@k8s-node02 ipvs]# vim /etc/sysconfig/modules/ipvs.modules
#!/bin/bash
for i in `ls /usr/lib/modules/3.10.0-957.el7.x86_64/kernel/net/netfilter/ipvs |grep -o "^[^.]*"`; do /sbin/modinfo -F filename $i &>/dev/null; if [ $? -eq 0 ]; then /sbin/modprobe $i; fi; don
[root@k8s-node02 ipvs]# chmod 755 /etc/sysconfig/modules/ipvs.modules && bash /etc/sysconfig/modules/ipvs.modules && lsmod | grep -e ip_vs -e nf_conntrack_ipv4
B) 由于ipvs已经加入到了内核的主干,所以为kube-proxy开启ipvs的前提需要加载以下的内核模块:
ip_vs
ip_vs_rr
ip_vs_wrr
ip_vs_sh
nf_conntrack_ipv4
在所有的Kubernetes节点node1和node2上执行以下脚本:
cat > /etc/sysconfig/modules/ipvs.modules <
接下来还需要确保各个节点上已经安装了ipset软件包yum install ipset。 为了便于查看ipvs的代理规则,最好安装一下管理工具ipvsadm yum install ipvsadm。
如果以上前提条件如果不满足,则即使kube-proxy的配置开启了ipvs模式,也会退回到iptables模式。
[root@k8s-node02 ~]# wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@k8s-node02 ~]# mv docker-ce.repo /etc/yum.repos.d/
[root@k8s-node02 yum.repos.d]# scp docker-ce.repo k8s-node01:/etc/yum.repos.d/
[root@k8s-node02 yum.repos.d]# scp docker-ce.repo k8s-master:/etc/yum.repos.d/
[root@k8s-master ~]# yum install -y docker-ce
[root@k8s-node01 yum.repos.d]# yum install -y docker-ce
[root@ k8s-node02 yum.repos.d]# yum install -y docker-ce
[root@k8s-master ~]# docker -v
Docker version 18.09.5, build e8ff056
[root@k8s-master ~]# vim /usr/lib/systemd/system/docker.service
Environment="HTTPS_PROXY=http://www.ik8s.io:10070" #设置代理
Environment="NO_PROXY=127.0.0.0/8,192.168.1.0/24" #访问次网络 不需要代理
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ExecstartPost=/usr/sbin/iptables -P FORWARD ACCEPT #新增 意思:启动docker的时候自动执行这个命令
[root@k8s-master ~]# systemctl daemon-reload
[root@k8s-master ~]# systemctl start docker
[root@k8s-node02 yum.repos.d]# ps -ef|grep docker
root 6617 1 1 10:55 ? 00:00:00 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
查看iptables
[root@k8s-master ~]# iptables -vnL
#阿里云的开源镜像站:https://mirrors.aliyun.com/kubernetes/
添加阿里云的镜像k8s:
[root@k8s-node02 yum.repos.d]# vim kubernetes.repo
[kubernetes]
name=k8s repo
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
查看repo文件
[root@k8s-node02 yum.repos.d]# yum repolist
[root@k8s-node02 yum.repos.d]# yum list|grep "^kube"
#master节点安装
[root@k8s-node02 yum.repos.d]# yum install -y kubeadm kubelet kubectl
[root@k8s-node02 yum.repos.d]# rpm -qa kubelet
kubelet-1.14.1-0.x86_64
[root@k8s-node02 yum.repos.d]# rpm -ql kubelet
/etc/kubernetes/manifests
/etc/sysconfig/kubelet
/usr/bin/kubelet
/usr/lib/systemd/system/kubelet.service
[root@k8s-node02 yum.repos.d]#
[root@k8s-node02 yum.repos.d]# vim /etc/sysconfig/kubelet
KUBELET_EXTRA_ARGS="--fail-swap-on=false"
A) 使用命令初始化
kubeadm init --kubernetes-version=v1.14.1 --apiserver-advertise-address=10.26.3.184 --pod-network-cidr=10.244.0.0/16 --ignore-preflight-errors=Swap
B)自己定义配置文件 使用--config来实现
k8s.gcr.io/kube-apiserver:v1.14.1
k8s.gcr.io/kube-controller-manager:v1.14.1
k8s.gcr.io/kube-scheduler:v1.14.1
k8s.gcr.io/kube-proxy:v1.14.1
k8s.gcr.io/pause:3.1
k8s.gcr.io/etcd:3.3.10
k8s.gcr.io/coredns:1.3.1
[root@k8s-master ~]# MY_REGISTRY=registry.cn-hangzhou.aliyuncs.com/openthings
[root@k8s-master ~]#docker pull ${MY_REGISTRY}/k8s-gcr-io-kube-apiserver:v1.14.1
[root@k8s-master ~]# docker pull ${MY_REGISTRY}/k8s-gcr-io-kube-controller-manager:v1.14.1
[root@k8s-master ~]# docker pull ${MY_REGISTRY}/k8s-gcr-io-kube-scheduler:v1.14.1
[root@k8s-master ~]# docker pull ${MY_REGISTRY}/k8s-gcr-io-kube-proxy:v1.14.1
[root@k8s-master ~]# docker pull ${MY_REGISTRY}/k8s-gcr-io-etcd:3.3.10
[root@k8s-master ~]# docker pull ${MY_REGISTRY}/k8s-gcr-io-pause:3.1
[root@k8s-master ~]#docker pull ${MY_REGISTRY}/k8s-gcr-io-coredns:1.3.1
[root@k8s-master ~]#docker tag ${MY_REGISTRY}/k8s-gcr-io-kube-apiserver:v1.14.1 k8s.gcr.io/kube-apiserver:v1.14.1
[root@k8s-master ~]#docker tag ${MY_REGISTRY}/k8s-gcr-io-kube-scheduler:v1.14.1 k8s.gcr.io/kube-scheduler:v1.14.1
[root@k8s-master ~]#docker tag ${MY_REGISTRY}/k8s-gcr-io-kube-controller-manager:v1.14.1 k8s.gcr.io/kube-controller-manager:v1.14.1
[root@k8s-master ~]#docker tag ${MY_REGISTRY}/k8s-gcr-io-kube-proxy:v1.14.1 k8s.gcr.io/kube-proxy:v1.14.1
[root@k8s-master ~]#docker tag ${MY_REGISTRY}/k8s-gcr-io-etcd:3.3.10 k8s.gcr.io/etcd:3.3.10
[root@k8s-master ~]# docker tag ${MY_REGISTRY}/k8s-gcr-io-pause:3.1 k8s.gcr.io/pause:3.1
[root@k8s-master ~]#docker tag ${MY_REGISTRY}/k8s-gcr-io-coredns:1.3.1 k8s.gcr.io/coredns:1.3.1
[root@k8s-master ~]# kubeadm init --kubernetes-version=v1.14.1 --pod-network-cidr=10.244.0.0/16 --service-cidr=10.96.0.0/12 --ignore-preflight-errors=Swap
最好找个文件记录下 防止后续使用到
Your Kubernetes control-plane 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/
Then you can join any number of worker nodes by running the following on each as root:
kubeadm join 192.168.1.101:6443 --token lzc69y.4gapyv735z0stisl \
--discovery-token-ca-cert-hash sha256:34ef3c3d00123569822285df5d084b3c062249e1a6726364821460d1a3833e1a
我这里直接使用root用户进行操作
[root@k8s-master ~]# mkdir .kube
[root@k8s-master ~]# cp -i /etc/kubernetes/admin.conf .kube/config
查看k8s的nodes
[root@k8s-master ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master NotReady master 18m v1.14.1
A) [root@k8s-master ~]#kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
#B) 下载kube-flannel.yml部署flannel #参考:https://blog.51cto.com/nhylovezyh/2377982?source=drt
链接:https://pan.baidu.com/s/1qqNuWOEeNu_k3HDacNJqcw
提取码:b0dh
[root@k8s-master ~]# kubectl apply -f kube-flannel.yml
[root@k8s-master ~]# kubectl get pods -n kube-system
转载于:https://blog.51cto.com/9025736/2385268