Kubertenes集群部署
Kubertenes集群部署系统环境系统环境初始化安装软件源配置安装docker 1.12.6安装kubernetes下载相关镜像初始化kubernetes集群初始化成功输出:查看集群节点信息:初始化集群报错及问题解决:安装网络插件:一、weave网络模式二、flannel网络模式添加节点安装dashboard安装heapster插件
本文档是使用kubeadm的方式来自动部署kubernetes集群
系统环境
操作系统:Centos 7.3
节点角色:172.17.1.52 k8s-master
172.17.1.53 k8s-slave
7.3
节点角色:172.17.1.52 k8s-master
172.17.1.53 k8s-slave
系统环境初始化
#关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
#修改内核参数
cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
#执行sysctl -p /etc/sysctl.d/k8s.conf生效(sysctl --system)
#如果有如下报错:
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
#解决方法:
安装bridge-util软件,加载bridge模块,加载br_netfilter模块
yum install -y bridge-utils.x86_64
modprobe bridge
modprobe br_netfilter
#关闭Selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
setenforce = 0
#关闭swap
swapoff -a
echo "vm.swappiness=0" >> /etc/sysctl.d/k8s.conf
systemctl stop firewalld
systemctl disable firewalld
#修改内核参数
cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
#执行sysctl -p /etc/sysctl.d/k8s.conf生效(sysctl --system)
#如果有如下报错:
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
#解决方法:
安装bridge-util软件,加载bridge模块,加载br_netfilter模块
yum install -y bridge-utils.x86_64
modprobe bridge
modprobe br_netfilter
#关闭Selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
setenforce = 0
#关闭swap
swapoff -a
echo "vm.swappiness=0" >> /etc/sysctl.d/k8s.conf
安装软件源配置
#配置k8s软件源
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
#配置docker软件源
cat <<EOF > /etc/yum.repos.d/docker.repo
[dockerrepo]
name=Docker
baseurl=https://yum.dockerproject.org/repo/main/centos/7
enabled=1
gpgcheck=0
EOF
#配置centos73的仓库源
cat <<EOF > /etc/yum.repos.d/local.repo
[local]
name=local
baseurl=http://172.17.1.80:8090/centos73
gpgcheck=0
enable=1
EOF
#配置k8s软件源
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
#配置docker软件源
cat <<EOF > /etc/yum.repos.d/docker.repo
[dockerrepo]
name=Docker
baseurl=https://yum.dockerproject.org/repo/main/centos/7
enabled=1
gpgcheck=0
EOF
#配置centos73的仓库源
cat <<EOF > /etc/yum.repos.d/local.repo
[local]
name=local
baseurl=http://172.17.1.80:8090/centos73
gpgcheck=0
enable=1
EOF
安装docker 1.12.6
docker-engine-1.12.6-1.el7.centos.x86_64.rpm
docker-engine-selinux-1.12.6-1.el7.centos.noarch.rpm
启动docker并设置开机启动
systemctl enable docker && systemctl start docker
启动docker并设置开机启动
systemctl enable docker && systemctl start docker
安装kubernetes
#查看软件包版本
yum list --showduplicates | grep 'kubeadm\|kubectl\|kubelet'
#安装软件
yum install -y kubelet kubeadm kubectl kubernetes-cni
#修改配置
sed -e 's/KUBELET_CGROUP_ARGS=--cgroup-driver=systemd/KUBELET_CGROUP_ARGS=--cgroup-driver=cgroupfs/' /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
#启动服务并设置开机自启
systemctl start kubelet && systemctl enable kubelet
#查看软件包版本
yum list --showduplicates | grep 'kubeadm\|kubectl\|kubelet'
#安装软件
yum install -y kubelet kubeadm kubectl kubernetes-cni
#修改配置
sed -e 's/KUBELET_CGROUP_ARGS=--cgroup-driver=systemd/KUBELET_CGROUP_ARGS=--cgroup-driver=cgroupfs/' /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
#启动服务并设置开机自启
systemctl start kubelet && systemctl enable kubelet
下载相关镜像
-
(可以在国内网站下载镜像然后修改tag)
Image Name | v1.7 release branch version | v1.8 release branch version |
---|---|---|
gcr.io/google_containers/kube apiserver-${ARCH} | v1.7.x | v1.8.x |
gcr.io/google_containers/kube-controller-manager-${ARCH} | v1.7.x | v1.8.x |
gcr.io/google_containers/kube-scheduler-${ARCH} | v1.7.x | v1.8.x |
gcr.io/google_containers/kube-proxy-${ARCH} | v1.7.x | v1.8.x |
gcr.io/google_containers/etcd-${ARCH} | 3.0.17 | 3.0.17 |
gcr.io/google_containers/pause-${ARCH} | 3.0 | 3.0 |
gcr.io/google_containers/k8s-dns-sidecar-${ARCH} | 1.14.4 | 1.14.4 |
gcr.io/google_containers/k8s-dns-kube-dns-${ARCH} | 1.14.4 | 1.14.4 |
gcr.io/google_containers/k8s-dns-dnsmasq-nanny-${ARCH} | 1.14.4 | 1.14.4 |
初始化kubernetes集群
kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=172.17.1.52 --skip-preflight-checks --kubernetes-version=v1.7.5
#重置集群节点状态
kubeadm reset
#配置kubectl命令执行权限
mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config
#设置master为不可调度
kubectl taint nodes k8s-master node-role.kubernetes.io/master=:NoSchedule
#解除配置,设置master可以被调度运行pod
kubectl taint nodes --all node-role.kubernetes.io/master-
kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=172.17.1.52 --skip-preflight-checks --kubernetes-version=v1.7.5
#重置集群节点状态
kubeadm reset
#配置kubectl命令执行权限
mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config
#设置master为不可调度
kubectl taint nodes k8s-master node-role.kubernetes.io/master=:NoSchedule
#解除配置,设置master可以被调度运行pod
kubectl taint nodes --all node-role.kubernetes.io/master-
初始化成功输出:
[root@k8s-master manifests]# kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=172.1