k8s|kubernetes1.20搭建笔记

一、安装docker

sudo yum remove docker* sudo yum install -y yum-utils#配置docker的yum地址 sudo yum-config-manager \ --add-repo \ http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo#安装指定版本 sudo yum install -y docker-ce-20.10.7 docker-ce-cli-20.10.7 containerd.io-1.4.6# 启动&开机启动docker systemctl enable docker --now# docker加速配置 # registry-mirrors 自己的阿里云镜像加速地址 # insecure-registries 私有镜像仓库 sudo mkdir -p /etc/docker sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://mbwkeham.mirror.aliyuncs.com"], "exec-opts": ["native.cgroupdriver=systemd"], "log-driver": "json-file", "log-opts": { "max-size": "100m" }, "storage-driver": "overlay2", "insecure-registries": ["192.168.2.1"] } EOF sudo systemctl daemon-reload sudo systemctl restart docker

二、安装Kubernetes 1、基本环境 【k8s|kubernetes1.20搭建笔记】每个机器使用内网ip互通
每个机器配置自己的hostname,不能用localhost
#设置每个机器自己的hostname hostnamectl set-hostname xxx# 将 SELinux 设置为 permissive 模式(相当于将其禁用) sudo setenforce 0 sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config#关闭swap swapoff -a sed -ri 's/.*swap.*/#&/' /etc/fstab#允许 iptables 检查桥接流量 cat <

2、安装kubelet、kubeadm、kubectl
#配置k8s的yum源地址 cat <> /etc/hosts

3、初始化master节点 1、初始化
kubeadm init \ --apiserver-advertise-address=192.168.2.xx \ --control-plane-endpoint=k8s-master \ --image-repository registry.cn-hangzhou.aliyuncs.com/lfy_k8s_images \ --kubernetes-version v1.20.9 \ --service-cidr=10.96.0.0/16 \ --pod-network-cidr=192.168.0.0/16

2、记录关键信息
Your Kubernetes control-plane has initialized successfully!To start using your cluster, you need to run the following as a regular user:mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/configAlternatively, if you are the root user, you can run:export KUBECONFIG=/etc/kubernetes/admin.confYou should now deploy a pod network to the cluster. Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at: https://kubernetes.io/docs/concepts/cluster-administration/addons/You can now join any number of control-plane nodes by copying certificate authorities and service account keys on each node and then running the following as root:kubeadm join k8s-master:6443 --token n8yyni.ce0wen7wuyyb4nro \ --discovery-token-ca-cert-hash sha256:feaae18ddacfe6971bf3030af54b145ad8c5937c06344920245d8b9f55644668 \ --control-plane Then you can join any number of worker nodes by running the following on each as root:kubeadm join k8s-master:6443 --token n8yyni.ce0wen7wuyyb4nro \ --discovery-token-ca-cert-hash sha256:feaae18ddacfe6971bf3030af54b145ad8c5937c06344920245d8b9f55644668

3、安装Calico网络插件
curl https://docs.projectcalico.org/manifests/calico.yaml -Okubectl apply -f calico.yaml

4、加入worker节点
kubeadm join k8s-master:6443 --token n8yyni.ce0wen7wuyyb4nro \ --discovery-token-ca-cert-hash sha256:feaae18ddacfe6971bf3030af54b145ad8c5937c06344920245d8b9f55644668

令牌过期可使用命令重新生产
#新令牌 kubeadm token create --print-join-command

    推荐阅读