服务器配置
服务器IP 主机名
192.168.80.1 master
192.168.80.2 node1
192.168.80.3 node2
安装docker 1、三台服务器安装docker源
[root@master ~]
[root@master ~]
2、安装docker
yum install -y docker-ce
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://483txl0m.mirror.aliyuncs.com"]
}
EOF
3、设置开机自启
systemctl enable docker && systemctl start docker
查看版本
docker --version
4、安装kubeadm、kubelet核kubectl
cat > /etc/yum.repos.d/kubernetes.repo << EOF
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
5、添加映射
cat <<EOF >>/etc/hosts
192.168.80.1 master
192.168.80.2 node1
192.168.80.3 node2
EOF
#指定安装版本
[root@master ~]
注:如果生产环境中,master隐藏,node节点被授权为master,也需安装,此次部署只在master上安装
[root@master ~]
#设置开机自启动
[root@master ~]
关闭swap分区
[root@master ~]
[root@master ~]
将桥接的IPv4流量传递到iptables的链
cat > /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
执行初始化
[root@master ~]
[root@master k8s]
> --apiserver-advertise-address=192.168.80.1 \
> --image-repository registry.aliyuncs.com/google_containers \
> --kubernetes-version v1.15.0 \
> --service-cidr=10.1.0.0/16 \
> --pod-network-cidr=10.244.0.0/16
使用kubectl工具
[root@master k8s]
[root@master k8s]
[root@master k8s]
#安装pod网络插件(flannel)
[root@master k8s]
[root@master k8s]
#查看组件状态 && 查看节点状态
[root@master k8s]
NAME STATUS MESSAGE ERROR
scheduler Healthy ok
controller-manager Healthy ok
etcd-0 Healthy {"health":"true"}
[root@master k8s]
NAME STATUS ROLES AGE VERSION
master Ready master 54m v1.15.0
node节点 docker 拉取flannel镜像
docker pull lizhenliang/flannel:v0.11.0-amd64
关闭swap分区
[root@node1 ~]
[root@node1 ~]
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
[root@node1 ~]
#添加节点(kubeadm join,节点token会周期性变化,kubeadm token list查看token)
[root@node1 ~]
master节点查看node状态 “三个ready”
[root@master k8s]
NAME STATUS ROLES AGE VERSION
master Ready master 156m v1.15.0
node1 Ready <none> 66m v1.15.0
node2 Ready <none> 6m27s v1.15.0
[root@master k8s]
打node标签
[root@master k8s]
[root@master k8s]
查看名称空间
[root@master k8s]
NAME STATUS AGE
default Active 3h10m
kube-node-lease Active 3h10m
kube-public Active 3h10m
kube-system Active 3h10m
查看pod名称空间
root@master k8s]
NAME READY STATUS RESTARTS AGE
coredns-bccdc95cf-257xp 1/1 Running 0 3h12m
coredns-bccdc95cf-qvzv5 1/1 Running 0 3h12m
etcd-master 1/1 Running 0 3h10m
kube-apiserver-master 1/1 Running 0 3h11m
kube-controller-manager-master 1/1 Running 0 3h11m
kube-flannel-ds-amd64-g2k7l 1/1 Running 0 161m
kube-flannel-ds-amd64-q8hqf 1/1 Running 0 42m
kube-flannel-ds-amd64-z627q 1/1 Running 0 102m
kube-proxy-dvqp4 1/1 Running 0 102m
kube-proxy-nz97w 1/1 Running 0 3h12m
kube-proxy-qnzxg 1/1 Running 0 42m
kube-scheduler-master 1/1 Running 0 3h11m
查看服务发现的资源
[root@master k8s]
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.1.0.1 <none> 443/TCP 3h18m
|