赞
踩
k8s几个概念
kubeadm:用于k8s集群部署
kubelet:Master在Node节点上的Agent,管理本机运行容器的生命周期
1.虚拟机准备
windows 下通过vm virtualbox 安装3台虚拟机(1个master,2个node)
cpu:2核
网络连接设置为桥接网卡,配置好网络后重启服务
关闭防火墙:
systemctl stop firewalld
systemctl disable firewalld
关闭swap:
swapoff -a # 临时关闭
sed -ri 's/.*swap.*/#&/' /etc/fstab #永久关闭
2.xshell 进入master,安装docker
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo yum -y install docker-ce-18.06.1.ce-3.el7 systemctl enable docker && systemctl start docker docker --version
3.添加kubernetes YUM软件源
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
4. 安装kubeadm,kubelet和kubectl
yum install -y kubelet-1.15.0 kubeadm-1.15.0 kubectl-1.15.0 systemctl enable kubelet
5.部署Kubernetes Master[master上执行]
kubeadm init --apiserver-advertise-address=172.16.1.xx --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
[ERROR FileContent--proc-sys-net-bridge-bridge-nf-call-iptables]: /proc/sys/net/bridge/bridge-nf-call-iptables contents are not set to 1
---解决:按提示设定为1
echo "1" >/proc/sys/net/ipv4/ip_forward
echo "1" >/proc/sys/net/bridge/bridge-nf-call-iptables
5.2 Kubeadm init 安装镜像卡住,采用如下脚本拉取镜像
- # kubeadm config images list --kubernetes-version v1.13.0 # 看下该版本下的镜像名
- # 拉取镜像
- docker pull mirrorgooglecontainers/kube-apiserver:v1.13.0
- docker pull mirrorgooglecontainers/kube-controller-manager:v1.13.0
- docker pull mirrorgooglecontainers/kube-scheduler:v1.13.0
- docker pull mirrorgooglecontainers/kube-proxy:v1.13.0
- docker pull mirrorgooglecontainers/pause:3.1
- docker pull mirrorgooglecontainers/etcd:3.2.24
- docker pull coredns/coredns:1.2.6
-
- # 重命名镜像标签
- docker tag docker.io/mirrorgooglecontainers/kube-proxy:v1.13.0 k8s.gcr.io/kube-proxy:v1.13.0
- docker tag docker.io/mirrorgooglecontainers/kube-scheduler:v1.13.0 k8s.gcr.io/kube-scheduler:v1.13.0
- docker tag docker.io/mirrorgooglecontainers/kube-apiserver:v1.13.0 k8s.gcr.io/kube-apiserver:v1.13.0
- docker tag docker.io/mirrorgooglecontainers/kube-controller-manager:v1.13.0 k8s.gcr.io/kube-controller-manager:v1.13.0
- docker tag docker.io/mirrorgooglecontainers/etcd:3.2.24 k8s.gcr.io/etcd:3.2.24
- docker tag docker.io/mirrorgooglecontainers/pause:3.1 k8s.gcr.io/pause:3.1
- docker tag docker.io/coredns/coredns:1.2.6 k8s.gcr.io/coredns:1.2.6
-
- # 删除旧镜像
- docker rmi docker.io/mirrorgooglecontainers/kube-proxy:v1.13.0
- docker rmi docker.io/mirrorgooglecontainers/kube-scheduler:v1.13.0
- docker rmi docker.io/mirrorgooglecontainers/kube-apiserver:v1.13.0
- docker rmi docker.io/mirrorgooglecontainers/kube-controller-manager:v1.13.0
- docker rmi docker.io/mirrorgooglecontainers/etcd:3.2.24
- docker rmi docker.io/mirrorgooglecontainers/pause:3.1
- docker rmi docker.io/coredns/coredns:1.2.6
6.安装Pod网络插件(CNI)
kubectl apply -fhttps://raw.githubusercontent.com/coreos/flannel/a70459be0084506e4ec919aa1c114638878db11b/Documentation/kube-flannel.yml
在node上安装flannel
docker pull lizhenliang/flannel:v0.11.0-amd64
kubeadm join 192.168.116.129:6443 --token iz96vy.f5ukew9geeome5is \ --discovery-token-ca-cert-hash sha256:72b689426bfc34512294c29b39ea3b2af3a94e39f62c4434f3a49f16d51a1382
查看node
kubectl get node
创建nginx容器
kubectlcreate deployment nginx --image=nginx
暴露对外端口
kubectl expose deployment nginx --port=80 --type=NodePort
查看nginx是否运行成功
kubectl get pod,svc
在浏览器访问。三个结点都可访问,说明集群已经搭建完成,
172.16.xx.xx:31173
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。