Kubernetes的单Master集群搭建

一、安装Docker(集群所有节点都配置)

所有节点安装 Docker/kubeadm/kubelet

1、安装 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

2、修改Docker的仓库地址为阿里云

登录阿里云容器镜像服务:https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors

二、安装kubeadm,kubelet 和 kubectl(集群所有节点都配置)

1、添加阿里云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

2、安装 kubeadm,kubelet 和 kubectl

yum install -y kubelet kubeadm kubectl

systemctl enable kubelet

三、kubeadm部署

1、部署Master节点

前置配置, 关闭 swap

 swapoff -a # 临时

 vim /etc/fstab # 永久

echo "1" >/proc/sys/net/bridge/bridge-nf-call-iptables
kubeadm init \
--apiserver-advertise-address=192.168.88.130 \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version v1.20.2 \
--service-cidr=10.96.0.0/12 \
--pod-network-cidr=10.244.0.0/16

2、 kubectl配置

当第一步执行完后,会有提示信息,使用提示信息执行kubectl配置

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config



export KUBECONFIG=/etc/kubernetes/admin.conf

3、注册node节点

kubeadm join 192.168.88.130:6443 --ignore-preflight-errors=Swap --token fmyhkp.jppeqtzk3upl1okr --discovery-token-ca-cert-hash sha256:6e7284ae3924bfb392cb271f3deb96c39abda8bbb9b0587356b47f789496aaa7

4、配置 Pod网络插件(CNI)(在master上执行)

kubectl apply -f  https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

执行的时候可能会报错,

解决方案:

在https://www.ipaddress.com/查询raw.githubusercontent.com的真实IP。
sudo vim /etc/hosts
199.232.28.133 raw.githubusercontent.com

5、查看k8s状态

kubectl get pods -n kube-system

kubectl get nodes

四、测试集群

1、创建一个测试的pod

kubectl create deployment nginx --image=nginx

kubectl expose deployment nginx --port=80 --type=NodePort

kubectl get pod,svc

访问地址:http://192.168.88.131:32406

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值