1. 程式人生 > >K8S部署--kubeadm

K8S部署--kubeadm

k8s

一、環境準備
操作系統   Centos 7.4
主機信息
kb-001  192.168.0.11
kb-002  192.168.0.12
kb-003  192.168.0.13

添加kube-master到kube-node的秘鑰認證
ssh-keygen
ssh-copy-id  主機名

安裝docker
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum-config-manager --enable docker-ce-edge
yum-config-manager --enable docker-ce-testing
yum-config-manager --disable docker-ce-edge
yum erase docker-engine-selinux -y
yum makecache fast
yum install -y docker-ce
mkdir -p /etc/systemd/system/docker.service.d
cat > /etc/systemd/system/docker.service.d/docker.conf <<EOF
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd --debug=false -s overlay  --graph=/data/docker/images --insecure-registry registry.xxxxxxxxxx.com -H unix:///var/run/docker.sock -H tcp://10.17.2.13:2371 $DOCKER_NETWORK_OPTIONS
EOF
格式化磁盤ftype  mkfs.xfs -n ftype=1 /dev/vdb
掛載:mkdir /data && mount /dev/vdb /data
service docker start

關閉SELinux 
sed -i ‘s#SELINUX=enforcing#SELINUX=disabled#g‘ /etc/selinux/config
setenforce 0 

關閉sawp分區
swapoff -a
vi /etc/fstab
註釋掉swap分區
#/dev/mapper/cl-swap     swap                    swap    defaults        0 0

關閉系統防火墻
systemctl stop firewalld
systemctl disable firewalld 

添加配置內核參數/etc/sysctl.d/k8s.conf文件
cat > /etc/sysctl.d/k8s.conf <<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
vm.swappiness = 0
EOF
sysctl -p /etc/sysctl.d/k8s.

或者
echo "net.bridge.bridge-nf-call-ip6tables = 1" >> /etc/sysctl.conf
echo "net.bridge.bridge-nf-call-iptables = 1" >> /etc/sysctl.conf
sysctl -p

#若問題
執行sysctl -p 時出現:
sysctl -p
sysctl: cannot stat /proc/sys/net/bridge/bridge-nf-call-ip6tables: No such file or directory
sysctl: cannot stat /proc/sys/net/bridge/bridge-nf-call-iptables: No such file or directory
解決方法:
modprobe br_netfilter
ls /proc/sys/net/bridge

安裝socat等工具
yum install -y ebtables socat

安裝kubernetes的時候,需要安裝kubelet, kubeadm等包,但k8s官網給的yum源是packages.cloud.google.com,國內訪問不了,此時我們可以使用阿裏雲的yum倉庫鏡像。

阿裏雲上沒有附Help說明連接,簡單摸索了下,如下設置可用(centos)。註意不要開啟check。

cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
        http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

配置防火墻
docker1.13以後將iptables的FORWARD默認設置為drop,因此要配置:
iptables -P FORWARD ACCEPT
service iptables save
並將該命令加入rc.local的exit之前

二、安裝Kube master組件

安裝kubeadm
yum install -y kubeadm

初始化管理節點
kubeadm init --kubernetes-version=1.9.4 --apiserver-advertise-address 192.168.1.11 --pod-network-cidr 10.244.0.0/16 --skip-preflight-checks

K8S部署--kubeadm