kubernetes 1.21 安装

安装一主(master)两从(node)kubernetes集群

1 基础环境准备

修改主机名
设置静态IP地址
关闭交换空间

 swapoff -a
vi /etc/fstab
#/swap.img      none    swap    sw      0       0

同步时间

dpkg-reconfigure tzdata
apt-det install ntpdate
ntpdate cn.pool.ntp.org
hwclock --systohc
date
hostname 操作系统(OS) 内存(Mem) CPU 存储(Storage)
kubernetes-master ubuntu-20.10-live-server-amd64 2 GB Core 2 20GB
kubernetes-slave1 ubuntu-20.10-live-server-amd64 2 GB Core 2 20GB
kubernetes-slave2 ubuntu-20.10-live-server-amd64 2 GB Core 2 20GB

2 确定机器之间互通,以及和外网通讯正常

kubernetes-master


kubernetes 1.21 安装_第1张图片
ping1.png

kubernetes-slave1


kubernetes 1.21 安装_第2张图片
ping2.png

kubernetes-slave2
kubernetes 1.21 安装_第3张图片
ping3.png

3 安装docker作为kubenate管理的容器

参照安装docker

4 在master节点上安装 kubelet kubeadm kubectl

#1 安装必要的一些系统工具
sudo apt-get update && sudo apt-get install -y apt-transport-https curl
#2 安装GPG证书
curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add - 
#3 添加kubernetes源地址(阿里云)
cat </etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF
#4 更新并安装kubelet kubeadm kubectl
apt-get update
apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl # 标记软件包,不进行更新
kubernetes 1.21 安装_第4张图片
kubeVersion.png

5 配置和初始化kubeadm

# 1 导出默认配置文件
mkdir  -p /usr/local/docker/kubernetes
cd /usr/local/docker/kubernetes/
kubeadm config print init-defaults --component-configs KubeletConfiguration > kubeadm.yml
# 2 编辑配置文件 kubeadm.yml
root@kubernetes-master:/usr/local/docker/kubernetes# vim kubeadm.yml 
root@kubernetes-master:/usr/local/docker/kubernetes# cat kubeadm.yml 
apiVersion: kubeadm.k8s.io/v1beta2
bootstrapTokens:
- groups:
  - system:bootstrappers:kubeadm:default-node-token
  token: abcdef.0123456789abcdef
  ttl: 24h0m0s
  usages:
  - signing
  - authentication
kind: InitConfiguration
localAPIEndpoint:
  advertiseAddress: 192.168.5.181 #update line  此处替换为自己master节点的IP
  bindPort: 6443
nodeRegistration:
  criSocket: /var/run/dockershim.sock
  name: kubernetes-master
  taints:
  - effect: NoSchedule
    key: node-role.kubernetes.io/master
---
apiServer:
  timeoutForControlPlane: 4m0s
apiVersion: kubeadm.k8s.io/v1beta2
certificatesDir: /etc/kubernetes/pki
clusterName: kubernetes
controllerManager: {}
dns:
  type: CoreDNS
etcd:
  local:
    dataDir: /var/lib/etcd
imageRepository: daocloud.io/daocloud # update line 修改下载镜像的源
kind: ClusterConfiguration
kubernetesVersion: v1.20.1 # update line 修改为 kubeVersion.png截图中你下载的版本
networking:
  dnsDomain: cluster.local
  podSubnet: "192.168.0.0/16" # Add line
  serviceSubnet: 10.96.0.0/12
scheduler: {}
---
apiVersion: kubelet.config.k8s.io/v1beta1
authentication:
  anonymous:
    enabled: false
  webhook:
    cacheTTL: 0s
    enabled: true
  x509:
    clientCAFile: /etc/kubernetes/pki/ca.crt
authorization:
  mode: Webhook
  webhook:
    cacheAuthorizedTTL: 0s
    cacheUnauthorizedTTL: 0s
cgroupDriver: cgroupfs
clusterDNS:
- 10.96.0.10
clusterDomain: cluster.local
cpuManagerReconcilePeriod: 0s
evictionPressureTransitionPeriod: 0s
fileCheckFrequency: 0s
healthzBindAddress: 127.0.0.1
healthzPort: 10248
httpCheckFrequency: 0s
imageMinimumGCAge: 0s
kind: KubeletConfiguration
logging: {}
nodeStatusReportFrequency: 0s
nodeStatusUpdateFrequency: 0s
resolvConf: /run/systemd/resolve/resolv.conf
rotateCertificates: true
runtimeRequestTimeout: 0s
shutdownGracePeriod: 0s
shutdownGracePeriodCriticalPods: 0s
staticPodPath: /etc/kubernetes/manifests
streamingConnectionIdleTimeout: 0s
syncFrequency: 0s
volumeStatsAggPeriod: 0s
3 根据配置文件拉去镜像
kubeadm config images pull --config kubeadm.yml
kubernetes 1.21 安装_第5张图片
mirrorRegistory.png
4 根据配置文件初始化kubeadm
kubeadm init --config=kubeadm.yaml --upload-certs | tee kubeadm-init.log
kubernetes 1.21 安装_第6张图片
installSuccess.png
#5.1 非ROOT用户执行
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
#5.2 ROOT用户执行
export KUBECONFIG=/etc/kubernetes/admin.conf

6 安装网络插件

kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml

7 kubenetes-node1 和 kubenetes-node2安装kubectl kubeadm kubelet(同master安装一样)

#1 安装必要的一些系统工具
sudo apt-get update && sudo apt-get install -y apt-transport-https curl
#2 安装GPG证书
curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add - 
#3 添加kubernetes源地址(阿里云)
cat </etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF
#4 更新并安装kubelet kubeadm kubectl
apt-get update
apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl # 标记软件包,不进行更新

8 kubenetes-node1 和 kubenetes-node2加入master节点中(installSuccess.png中倒数第二行)

在master初始化成功kubeadm的倒数第二行信息(或者kubeadm-init.log中) 不要复制

kubeadm join 192.168.5.181:6443 --token abcdef.0123456789abcdef \
    --discovery-token-ca-cert-hash sha256:0f0569ecd41c57f40e9f8a57d7f521e9b3182fc5383cee94af419754b1459186 

安装完成,在master上查看nodes

# watch kubectl get pods --all-namespaces
kubectl get nodes
image.png
kubernetes 1.21 安装_第7张图片
image.png

kubernetes 1.21 安装_第8张图片
image.png

注释 - --port=0,重启kubelet

vim /etc/kubernetes/manifests/kube-controller-manager.yaml
vim /etc/kubernetes/manifests/kube-scheduler.yaml
systemctl restart kubelet.service
kubernetes 1.21 安装_第9张图片
image.png

你可能感兴趣的:(kubernetes 1.21 安装)