k8s通过kubeadm部署(1.20)

k8s通过kubeadm部署(1.20)

   张吉吉     2021年4月23日 11:29     304    

1、关闭三个服务

1.防火墙

systemctl stop firewalld

2.Selinux

Setenforce 0

3.swap分区

swapoff –a

 

2、修改主机名,添加hosts文件

hostnamectl set-hostname kuber-master

hostnamectl set-hostname kuber-work1

hostnamectl set-hostname kuber-work2

修改/etc/hosts文件

 

3、修改内核参数

cat > /etc/sysctl.d/k8s.conf << EOF

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

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

echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf

EOF

 

4、安装docker/kubedam/kubelet

1)安装docker

https://www.yunweigonghui.com/column/Docker/44/

2)安装kubeadm/kubelet

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

 

yum remove -y kubelet-1.20.0 kubeadm-1.20.0 kubectl-1.20.0

yum install -y kubelet-1.20.0 kubeadm-1.20.0 kubectl-1.20.0

systemctl enable kubelet.service

 

5、部署k8s master节点

kubeadm init

--kubernetes-version=1.20.0

--apiserver-advertise-address=192.168.0.218

--image-repository registry.aliyuncs.com/google_containers

--service-cidr=10.10.0.0/16

--pod-network-cidr=10.122.0.0/16

执行下边指令

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

 

6、安装flannel网络插件

这里使用flannel

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

 

7、添加node节点

这里根据上边初始化的master节点提供的信息为准

kubeadm join 192.168.0.218:6443 --token nmg23p.0w7cu6io9jw07lpc

--discovery-token-ca-cert-hash sha256:eb68defbfb7357c25deb3dddac82ea51c07fd3248494786d8ae61ef57caf3cf8

 

8、添加集群示例

kubectl create deployment nginx --image=nginx

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

kubectl get pod,svc

kubectl scale deployment nginx --replicas=3


文章评论

0

其他文章