Ubuntu 20 LTS 安装kubenetes 1.25

参考

环境

OS:Ubuntu 20 LTS
k8s: 1.25
docker:20.10.18

修改主机名

10.1.1.30
hostnamectl set-hostname master
10.1.1.31
hostnamectl set-hostname node1

设置hosts

cat <<EOF | tee /etc/hosts
127.0.0.1   localhost.localdomain   localhost
::1         localhost6.localdomain6 localhost6
10.1.1.30   master
10.1.1.31   node1
EOF

禁用swap

swapoff -a # 临时关闭
sed -ri 's/.*swap.*/#&/' /etc/fstab  #永久关闭
free -h

开启转发

cat <<EOF | tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-iptables  = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward                 = 1
EOF
sysctl -p

安装docker

# 依赖
apt-get update
apt-get install -y ca-certificates curl gnupg lsb-release net-tools
# gpg密钥
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list
# 安装docker
apt-get update
apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin

安装cri-dockerd

docker在k8s1.24之后不再是默认运行时,需要安装cri-dockerd

wget https://ghproxy.com/https://github.com/Mirantis/cri-dockerd/releases/download/v0.2.5/cri-dockerd_0.2.5.3-0.ubuntu-jammy_amd64.deb
dpkg -i cri-dockerd_0.2.5.3-0.ubuntu-jammy_amd64.deb
sed -i -e 's#ExecStart=.*#ExecStart=/usr/bin/cri-dockerd --network-plugin=cni --pod-infra-container-image=registry.aliyuncs.com/google_containers/pause:3.8#g' /usr/lib/systemd/system/cri-docker.service
systemctl daemon-reload
systemctl enable cri-docker

安装k8s

# 安装依赖
apt-get update
apt-get install -y apt-transport-https curl
# 下载 Google Cloud 公开签名秘钥
curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg  https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg
# 添加 Kubernetes apt 仓库
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] http://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial main" | tee /etc/apt/sources.list.d/kubernetes.list
# 更新 apt 包索引,安装 kubelet、kubeadm 和 kubectl,并锁定其版本
apt-get update
apt-get install -y kubelet kubeadm kubectl
apt-mark hold kubelet kubeadm kubectl
# systemctl start kubelet
# systemctl enable kubelet

初始化k8s集群

注意docker下载的pause镜像可能是3.8,需要修改/usr/lib/systemd/system/cri-docker.service,重启cri-docker

注意初始化不成功使用kubeadm reset之后删除/var/lib/etcd目录

注意node初始化需要加上–cri-socket /var/run/cri-dockerd.sock参数

kubeadm config images pull --cri-socket=unix:///var/run/cri-dockerd.sock \--image-repository registry.aliyuncs.com/google_containerskubeadm init --image-repository registry.aliyuncs.com/google_containers \--apiserver-advertise-address=10.1.1.30 \--service-cidr=192.168.200.0/21 \--pod-network-cidr=10.10.0.0/16 \--cri-socket /var/run/cri-dockerd.sock# 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/config# Alternatively, if you are the root user, you can run:#   export KUBECONFIG=/etc/kubernetes/admin.conf# You 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/# Then you can join any number of worker nodes by running the following on each as root:# kubeadm join 10.1.1.30:6443 --token 7dn4wz.v7uhvkf55b2vvi2h \
#         --discovery-token-ca-cert-hash sha256:3ebd007a152158a603af63aa6f8fd28247a015f4c183504037d003fb7fc9ecfb # node节点加入后
kubectl get nodes

安装calico

wget https://raw.githubusercontent.com/projectcalico/calico/v3.24.1/manifests/tigera-operator.yaml
kubectl create -f tigera-operator.yaml
wget https://raw.githubusercontent.com/projectcalico/calico/v3.24.1/manifests/custom-resources.yaml
# 修改cidr地址custom-resources.yaml为10.10.0.0/16
# # This section includes base Calico installation configuration.
# # For more information, see: https://projectcalico.docs.tigera.io/master/reference/installation/api#operator.tigera.io/v1.Installation
# apiVersion: operator.tigera.io/v1
# kind: Installation
# metadata:
#   name: default
# spec:
#   # Configures Calico networking.
#   calicoNetwork:
#     # Note: The ipPools section cannot be modified post-install.
#     ipPools:
#     - blockSize: 26
#       cidr: 10.10.0.0/16
#       encapsulation: VXLANCrossSubnet
#       natOutgoing: Enabled
#       nodeSelector: all()# ---# # This section configures the Calico API server.
# # For more information, see: https://projectcalico.docs.tigera.io/master/reference/installation/api#operator.tigera.io/v1.APIServer
# apiVersion: operator.tigera.io/v1
# kind: APIServer
# metadata:
#   name: default
# spec: {}
kubectl create -f custom-resources.yaml

查看pods

kubectl get pod -A
# root@master:~# kubectl get pod -A
# NAMESPACE         NAME                                       READY   STATUS              RESTARTS        AGE
# calico-system     calico-kube-controllers-864f96fccc-nhxqc   0/1     Pending             0               28s
# calico-system     calico-node-gr674                          0/1     Init:1/2            0               28s
# calico-system     calico-typha-6559dcb5b7-5bmvf              0/1     ContainerCreating   0               28s
# kube-system       coredns-c676cc86f-4w57c                    0/1     Pending             0               6m11s
# kube-system       coredns-c676cc86f-lpbmf                    0/1     Pending             0               6m11s
# kube-system       etcd-master                                1/1     Running             2 (7m7s ago)    6m27s
# kube-system       kube-apiserver-master                      1/1     Running             1 (6m46s ago)   6m28s
# kube-system       kube-controller-manager-master             1/1     Running             1 (7m7s ago)    6m25s
# kube-system       kube-proxy-fz4qg                           1/1     Running             0               6m11s
# kube-system       kube-scheduler-master                      1/1     Running             1 (7m2s ago)    6m25s
# tigera-operator   tigera-operator-6675dc47f4-zq4kv           1/1     Running             0               6m1s

故障排查

很多故障可以通过重启kubelet,docker和cri-docker服务解决

测试集群

# vim nginx.yaml
apiVersion: apps/v1
kind: Deployment
metadata:name: nginx-deployment
spec:selector:matchLabels:app: nginxreplicas: 1template:metadata:labels:app: nginxspec:containers:- name: nginximage: nginx:1.23.1ports:- containerPort: 80---apiVersion: v1
kind: Service
metadata:name: nginx-service
spec:selector:app: nginxports:- protocol: TCPport: 80targetPort: 80nodePort: 30080type: NodePort
# 创建
kubectl create -f nginx.yaml
kubectl get pod -A
# root@master:~# kubectl get pod,node -A -o wide
# NAMESPACE          NAME                                           READY   STATUS    RESTARTS       AGE     IP              NODE     NOMINATED NODE   READINESS GATES
# calico-apiserver   pod/calico-apiserver-7ff967447f-qp55p          1/1     Running   0              7m43s   10.10.166.130   node1    <none>           <none>
# calico-apiserver   pod/calico-apiserver-7ff967447f-sdfzq          1/1     Running   0              7m43s   10.10.219.69    master   <none>           <none>
# calico-system      pod/calico-kube-controllers-864f96fccc-nhxqc   1/1     Running   0              98m     10.10.219.67    master   <none>           <none>
# calico-system      pod/calico-node-7j628                          1/1     Running   0              96m     10.1.1.31       node1    <none>           <none>
# calico-system      pod/calico-node-gr674                          1/1     Running   0              98m     10.1.1.30       master   <none>           <none>
# calico-system      pod/calico-typha-6559dcb5b7-5bmvf              1/1     Running   0              98m     10.1.1.30       master   <none>           <none>
# calico-system      pod/csi-node-driver-55vnx                      2/2     Running   0              97m     10.10.219.65    master   <none>           <none>
# calico-system      pod/csi-node-driver-6c4rc                      2/2     Running   0              8m29s   10.10.166.129   node1    <none>           <none>
# default            pod/nginx-deployment-665fc7dc59-t7g9h          1/1     Running   0              2m39s   10.10.166.131   node1    <none>           <none>
# kube-system        pod/coredns-c676cc86f-4w57c                    1/1     Running   0              104m    10.10.219.66    master   <none>           <none>
# kube-system        pod/coredns-c676cc86f-lpbmf                    1/1     Running   0              104m    10.10.219.68    master   <none>           <none>
# kube-system        pod/etcd-master                                1/1     Running   2 (105m ago)   104m    10.1.1.30       master   <none>           <none>
# kube-system        pod/kube-apiserver-master                      1/1     Running   1 (104m ago)   104m    10.1.1.30       master   <none>           <none>
# kube-system        pod/kube-controller-manager-master             1/1     Running   1 (105m ago)   104m    10.1.1.30       master   <none>           <none>
# kube-system        pod/kube-proxy-fz4qg                           1/1     Running   0              104m    10.1.1.30       master   <none>           <none>
# kube-system        pod/kube-proxy-h2t8v                           1/1     Running   0              96m     10.1.1.31       node1    <none>           <none>
# kube-system        pod/kube-scheduler-master                      1/1     Running   1 (105m ago)   104m    10.1.1.30       master   <none>           <none>
# tigera-operator    pod/tigera-operator-6675dc47f4-zq4kv           1/1     Running   0              104m    10.1.1.30       master   <none>           <none># NAMESPACE   NAME          STATUS   ROLES           AGE    VERSION   INTERNAL-IP   EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION      CONTAINER-RUNTIME
#             node/master   Ready    control-plane   104m   v1.25.2   10.1.1.30     <none>        Ubuntu 20.04.5 LTS   5.4.0-126-generic   docker://20.10.18
#             node/node1    Ready    <none>          96m    v1.25.2   10.1.1.31     <none>        Ubuntu 20.04.5 LTS   5.4.0-126-generic   docker://20.10.18# 访问http://10.1.1.30:30080

常用命令

# 排查kubelet故障
journalctl -xeu kubelet -f
# 查看pods和node
kubectl get pod,node -A -o wide
# 查看某个pod日志
kubectl logs calico-node-7j628 -n calico-system -f

Ubuntu 20 LTS 安装kubenetes 1.25相关推荐

  1. Ubuntu 20.04安装Ros Noetic及Ubuntu 18.04安装ROS Melodic(两版本详细填坑)

    Ubuntu 20.04安装Ros Noetic及18.04安装ROS Melodic 表1-1 ROS的历史版本 1. 设置安装源 2. 添加秘钥 3. 更新列表 4. 开始安装 5. 配置ROS环 ...

  2. Ubuntu Desktop LTS - 安装 64 位谷歌 Chrome 浏览器

    Ubuntu Desktop LTS - 安装 64 位谷歌 Chrome 浏览器 1. 下载源加入到系统的源列表 sudo wget http://www.linuxidc.com/files/re ...

  3. ubuntu 20.04 安装obs 录屏软件

    obs是一个非常好用的录屏软件,我们在windows安装和使用是非常的简单,但是在ubuntu安装还是比较麻烦的,需要使用命令行,还需要很多的依赖. 修改源 deb http://archive.ub ...

  4. ubuntu 20.04 安装synergy 记录

    ubuntu 20.04 安装synergy 记录 安装linux版时的问题 qt4 libcurl3 安装完启动时出现警告 synergy下载要收费,不过可以在csdn下载到资源! 安装linux版 ...

  5. ubuntu 20.04 安装 vlc、vlc-qt

    ubuntu 20.04 安装 vlc.vlc-qt 前言:众所周知安装一个软件,系统环境与软件版本是非常重要的,我在安装 vlc 与 vlc-qt 的时候走过很多弯路,下面将我遇到的一些问题(有些记 ...

  6. Ubuntu 20.04安装、显卡驱动配置及搜狗输入法配置(U盘离线安装、vi编辑器,esc ZZ,tty3模式)(一)

    小白装Ubuntu20.04-系列记录(一) 目录 小白装Ubuntu20.04-系列记录(一) Ubuntu 20.04安装 显卡驱动配置(U盘离线安装.vi编辑器,esc ZZ,tty3模式) 搜 ...

  7. ubuntu18.0.4 不能下载 libgd2-dev(ubuntu 20.04 安装perl 中GD 模块失败的解决办法)

    ubuntu18.0.4 不能下载 libgd2-dev 一.错误信息: Unable to locate package libgd2-dev 二.原因 没有对应源 到 https://packag ...

  8. Win10 和 Ubuntu 20.04 安装 face_recognition 和 dlib

    face_recognition是一个人脸识别库. WIN10安装: 首先改一下下载源: 1.C:\Users\xx\pip,新建文件pip.ini 2.文件里面输入: [global] index- ...

  9. ubuntu 20.04安装各类软件

    ubuntu 20.04安装各类软件 一.前言 ubuntu 20.04安装后,我输入gcc -v,出现了下面的情况,差点裂开了,20.04居然没有自带gcc编译器,以前安装的版本12.04 16.0 ...

最新文章

  1. python网络爬虫工程师薪资-月薪2万的爬虫工程师,Python需要学到什么程度?
  2. C#学习笔记之线程 - 同步上下文
  3. hdu 2160 母猪的故事(睡前随机水一发)(斐波那契数列)
  4. FreeType(字体渲染引擎):支持多种字体格式(TTF,TTC等)
  5. STM32F1如何切换到不同的型号
  6. Longest Substring With At Most K Distinct Characters
  7. Android学习笔记----ArcGIS在线地图服务(Android API)坐标纠偏
  8. 九零后女孩币圈变形记
  9. 吴恩达神经网络和深度学习-学习笔记-38-使用开源的方案+迁移学习+数据增强data augmentation
  10. Kubernetes详解(十四)——Pod对象生命周期
  11. Apache站点下载大文件不完整原因及解决办法
  12. SVN删除或新建(添加)文件
  13. CPA、CPS、CPC、CPM推广是什么意思
  14. flashfxp配置文件服务器同步,如何导出FlashFXP的站点配置文件
  15. 360极速浏览器插件不见了
  16. 光盘在服务器上装系统,如何通过DELL引导光盘在戴尔11G服务器上安装Win2003操作系统?.docx...
  17. You are a Badass: how to stop doubting your greatness and start living an awesome life, Jen Sincero
  18. ❌ Exiting due to GUEST_PROVISION: Failed to cache ISO: unable to cache ISO:
  19. Http/Https代理Python实现
  20. 一念起,万水千山;一念灭,沧海桑田。

热门文章

  1. vue项目使用视频播放器vue-video-player
  2. DellLee Vue学习笔记
  3. 网络训练时候loss不下降
  4. android设置wifi区域码,Android P - WiFi 国家码设置流程
  5. Eclipse离线下载安装Svn插件
  6. 巨杉数据库学习笔记+巨杉数据库实操项目实践
  7. Bug管理的流程和几个重点_悟sphenic_新浪博客
  8. 记录2019年华为实习生面试
  9. uni-app 打包之后日志输出和调试
  10. 云服务器搭建调查问卷系统,云服务器搭建调查问卷系统