ToB企服应用市场:ToB评测及商务社交产业平台

标题: arm架构 uos操作系统离线安装k8s [打印本页]

作者: 王國慶    时间: 昨天 11:38
标题: arm架构 uos操作系统离线安装k8s
目录
操作系统信息
安装文件准备
主机准备
主机设置
设置hosts(全部节点)
关闭防火墙、selinux、swap、dnsmasq(全部节点)
系统参数设置(全部节点)
设置ipvs功能(全部节点)
安装docker(全部节点)
卸载老版本
安装docker
安装
添加 system启动
 设置cgroupd
k8s准备和安装
安装 kubeadm,kubelet 和 kubectl(全部节点)
准备镜像(全部节点)
安装 master(master节点)
安装kubernets node(node节点)
安装kubernets 网络插件 calico(master节点操作)



操作系统信息

  1. uname -a  # 查看所有操作系统信息
  2. uname -s  # 查看内核名称
  3. uname -r  # 查看内核版本号
  4. uname -m  # 查看机器硬件名称
复制代码
 

  1. cat /etc/os-release  # 查看所有操作系统信息
复制代码
 

安装文件准备



主机准备

主机设置

172.171.16.88 meng  
备注:本次只是为了测试整个离线安装过程,只用了一个节点,多个节点,同理把node节点加入进去即可。
上传好全部安装需要的文件后,断网,在假造机安装界面操作,确保整个流程是断网的。


设置hosts(全部节点)

设置  /etc/hosts 文件
  1. cat >> /etc/hosts << EOF
  2. 172.171.16.88 meng
  3. EOF
复制代码
关闭防火墙、selinux、swap、dnsmasq(全部节点)

关闭防火墙
  1. systemctl stop firewalld
  2. systemctl disable firewalld
复制代码

关闭selinux
  1. sed -i 's/enforcing/disabled/' /etc/selinux/config  #永久
  2. setenforce 0  #临时
复制代码

关闭swap(k8s禁止假造内存以提高性能)
  1. sed -ri 's/.*swap.*/#&/' /etc/fstab #永久
  2. swapoff -a #临时
复制代码
//关闭dnsmasq(否则可能导致docker容器无法解析域名)
  1. service dnsmasq stop
  2. systemctl disable dnsmaq
复制代码
系统参数设置(全部节点)

//制作设置文件 设置网桥参数
mkdir /etc/sysctl.d
vim /etc/sysctl.d/kubernetes.conf
  1. net.bridge.bridge-nf-call-ip6tables = 1
  2. net.bridge.bridge-nf-call-iptables = 1
  3. net.ipv4.ip_forward = 1
  4. vm.swappiness=0
  5. vm.overcommit_memory = 1
  6. vm.panic_on_oom = 0
  7. fs.inotify.max_user_watches = 89100
复制代码
/生效文件
sysctl -p /etc/sysctl.d/kubernetes.conf
假如报错:
  1. [root@crawler-k8s-master ~]# sysctl -p /etc/sysctl.d/kubernetes.conf
  2. sysctl: cannot stat /proc/sys/net/bridge/bridge-nf-call-ip6tables: 没有那个文件或目录
  3. sysctl: cannot stat /proc/sys/net/bridge/bridge-nf-call-iptables: 没有那个文件或目录
复制代码
//加载网桥过滤模块
modprobe  br_netfilter
然后再次  
sysctl -p /etc/sysctl.d/kubernetes.conf
设置ipvs功能(全部节点)

在kubernetes中service有两种代理模型,一种是基于iptables的,一种是基于ipvs的
两者比较的话,ipvs的性能显着要高一些,但是假如要使用它,需要手动载入ipvs模块
//添加需要加载的模块写入脚本文件
vim /etc/sysconfig/modules/ipvs.modules
  1. #!/bin/bash
  2. modprobe -- ip_vs
  3. modprobe -- ip_vs_rr
  4. modprobe -- ip_vs_wrr
  5. modprobe -- ip_vs_sh
  6. modprobe -- nf_conntrack_ipv4
复制代码
//为脚本文件添加实行权限
chmod +x /etc/sysconfig/modules/ipvs.modules
//实行脚本文件
/bin/bash /etc/sysconfig/modules/ipvs.modules
备注:假如报错可能是需要将 modprobe -- nf_conntrack_ipv4  改为modprobe -- nf_conntrack
安装docker(全部节点)

卸载老版本

备注:docker版本最好用本文中提到的20.10,我再25版本上的docker安装报错,重装了20.10版本,立刻就可以了
  1. yum remove docker docker-client  docker-client-latest  docker-common docker-latest  docker-latest-logrotate docker-logrotate docker-engine
复制代码
安装docker

docker  安装包在准备文件的 docker目录下,上传到服务器
安装

  1. tar xf docker-20.10.9.tgz
  2. mv docker/* /usr/bin/
复制代码
添加 system启动

编辑docker的系统服务文件
  1. vim /usr/lib/systemd/system/docker.service
复制代码
  1. [Unit]
  2. Description=Docker Application Container Engine
  3. Documentation=https://docs.docker.com
  4. After=network-online.target firewalld.service
  5. Wants=network-online.target
  6. [Service]
  7. Type=notify
  8. ExecStart=/usr/bin/dockerd
  9. ExecReload=/bin/kill -s HUP $MAINPID
  10. LimitNOFILE=infinity
  11. LimitNPROC=infinity
  12. TimeoutStartSec=0
  13. Delegate=yes
  14. KillMode=process
  15. Restart=on-failure
  16. StartLimitBurst=3
  17. StartLimitInterval=60s
  18. [Install]
  19. WantedBy=multi-user.target
复制代码
 设置自启动
  1. systemctl start docker & systemctl enable docker
复制代码
 设置cgroupd

  1. vim /etc/docker/daemon.json
复制代码
  1. {
  2.           "exec-opts": ["native.cgroupdriver=systemd"]
  3. }
复制代码
  1. //设置开机启动
  2. systemctl start docker
  3. systemctl enable docker
  4. //重启docker
  5. systemctl daemon-reload
  6. systemctl restart docker
复制代码
k8s准备和安装

安装 kubeadm,kubelet 和 kubectl(全部节点)

安装包在 准备文件的 k8s-rpm下,上传到服务器/home 下

工具说明:

安装:
  1. cd /home/k8s-rpm
  2. rpm -ivh *.rpm
  3. rpm -ivh *.rpm --force --nodeps
复制代码
大概一个个安装 提示有依靠没装,就先装依靠 
设置开机自启动:
  1. systemctl start kubelet && systemctl enable kubelet
复制代码

准备镜像(全部节点)

安装包在 准备文件的 k8s-images下,上传到服务器/home 下

解压
  1. ​​​​​​​cd /home/k8s-images/
  2. find /home/k8s-images -name "*.tar" -exec docker load -i {} \;
复制代码
 解压完成后

安装 master(master节点)

  1. kubeadm init --apiserver-advertise-address=172.171.16.147 --image-repository registry.aliyuncs.com/google_containers --kubernetes-version v1.23.7 --service-cidr=10.96.0.0/16 --pod-network-cidr=10.244.0.0/16
复制代码
日志如下:
  1. [init] Using Kubernetes version: v1.23.7
  2. [preflight] Running pre-flight checks
  3. [preflight] Pulling images required for setting up a Kubernetes cluster
  4. [preflight] This might take a minute or two, depending on the speed of your internet connection
  5. [preflight] You can also perform this action in beforehand using 'kubeadm config images pull'
  6. [certs] Using certificateDir folder "/etc/kubernetes/pki"
  7. [certs] Generating "ca" certificate and key
  8. [certs] Generating "apiserver" certificate and key
  9. [certs] apiserver serving cert is signed for DNS names [crawler-k8s-master kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local] and IPs [10.96.0.1 172.171.16.147]
  10. [certs] Generating "apiserver-kubelet-client" certificate and key
  11. [certs] Generating "front-proxy-ca" certificate and key
  12. [certs] Generating "front-proxy-client" certificate and key
  13. [certs] Generating "etcd/ca" certificate and key
  14. [certs] Generating "etcd/server" certificate and key
  15. [certs] etcd/server serving cert is signed for DNS names [crawler-k8s-master localhost] and IPs [172.171.16.147 127.0.0.1 ::1]
  16. [certs] Generating "etcd/peer" certificate and key
  17. [certs] etcd/peer serving cert is signed for DNS names [crawler-k8s-master localhost] and IPs [172.171.16.147 127.0.0.1 ::1]
  18. [certs] Generating "etcd/healthcheck-client" certificate and key
  19. [certs] Generating "apiserver-etcd-client" certificate and key
  20. [certs] Generating "sa" key and public key
  21. [kubeconfig] Using kubeconfig folder "/etc/kubernetes"
  22. [kubeconfig] Writing "admin.conf" kubeconfig file
  23. [kubeconfig] Writing "kubelet.conf" kubeconfig file
  24. [kubeconfig] Writing "controller-manager.conf" kubeconfig file
  25. [kubeconfig] Writing "scheduler.conf" kubeconfig file
  26. [kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
  27. [kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
  28. [kubelet-start] Starting the kubelet
  29. [control-plane] Using manifest folder "/etc/kubernetes/manifests"
  30. [control-plane] Creating static Pod manifest for "kube-apiserver"
  31. [control-plane] Creating static Pod manifest for "kube-controller-manager"
  32. [control-plane] Creating static Pod manifest for "kube-scheduler"
  33. [etcd] Creating static Pod manifest for local etcd in "/etc/kubernetes/manifests"
  34. [wait-control-plane] Waiting for the kubelet to boot up the control plane as static Pods from directory "/etc/kubernetes/manifests". This can take up to 4m0s
  35. [apiclient] All control plane components are healthy after 12.507186 seconds
  36. [upload-config] Storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace
  37. [kubelet] Creating a ConfigMap "kubelet-config-1.23" in namespace kube-system with the configuration for the kubelets in the cluster
  38. NOTE: The "kubelet-config-1.23" naming of the kubelet ConfigMap is deprecated. Once the UnversionedKubeletConfigMap feature gate graduates to Beta the default name will become just "kubelet-config". Kubeadm upgrade will handle this transition transparently.
  39. [upload-certs] Skipping phase. Please see --upload-certs
  40. [mark-control-plane] Marking the node crawler-k8s-master as control-plane by adding the labels: [node-role.kubernetes.io/master(deprecated) node-role.kubernetes.io/control-plane node.kubernetes.io/exclude-from-external-load-balancers]
  41. [mark-control-plane] Marking the node crawler-k8s-master as control-plane by adding the taints [node-role.kubernetes.io/master:NoSchedule]
  42. [bootstrap-token] Using token: i4dp7i.7t1j8ezmgwkj1gio
  43. [bootstrap-token] Configuring bootstrap tokens, cluster-info ConfigMap, RBAC Roles
  44. [bootstrap-token] configured RBAC rules to allow Node Bootstrap tokens to get nodes
  45. [bootstrap-token] configured RBAC rules to allow Node Bootstrap tokens to post CSRs in order for nodes to get long term certificate credentials
  46. [bootstrap-token] configured RBAC rules to allow the csrapprover controller automatically approve CSRs from a Node Bootstrap Token
  47. [bootstrap-token] configured RBAC rules to allow certificate rotation for all node client certificates in the cluster
  48. [bootstrap-token] Creating the "cluster-info" ConfigMap in the "kube-public" namespace
  49. [kubelet-finalize] Updating "/etc/kubernetes/kubelet.conf" to point to a rotatable kubelet client certificate and key
  50. [addons] Applied essential addon: CoreDNS
  51. [addons] Applied essential addon: kube-proxy
  52. Your Kubernetes control-plane has initialized successfully!
  53. To start using your cluster, you need to run the following as a regular user:
  54.   mkdir -p $HOME/.kube
  55.   sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  56.   sudo chown $(id -u):$(id -g) $HOME/.kube/config
  57. Alternatively, if you are the root user, you can run:
  58.   export KUBECONFIG=/etc/kubernetes/admin.conf
  59. You should now deploy a pod network to the cluster.
  60. Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
  61.   https://kubernetes.io/docs/concepts/cluster-administration/addons/
  62. Then you can join any number of worker nodes by running the following on each as root:
  63. kubeadm join 172.171.16.147:6443 --token i4dp7i.7t1j8ezmgwkj1gio \
  64.         --discovery-token-ca-cert-hash sha256:9fb74686ff3bea5769e5ed466dbb2c32ed3fc920374ff2175b39b8162ac27f8f
复制代码
 在 master上进一步实行上面提示的下令
  1. mkdir -p $HOME/.kube
  2. cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  3. chown $(id -u):$(id -g) $HOME/.kube/config
复制代码
安装kubernets node(node节点)

将 node 添加到集群中
  1. kubeadm join 172.171.16.147:6443 --token i4dp7i.7t1j8ezmgwkj1gio \
  2.         --discovery-token-ca-cert-hash sha256:9fb74686ff3bea5769e5ed466dbb2c32ed3fc920374ff2175b39b8162ac27f8f
复制代码
然后表现日志:
  1. [preflight] Running pre-flight checks
  2. [preflight] Reading configuration from the cluster...
  3. [preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
  4. [kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
  5. [kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
  6. [kubelet-start] Starting the kubelet
  7. [kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap...
  8. This node has joined the cluster:
  9. * Certificate signing request was sent to apiserver and a response was received.
  10. * The Kubelet was informed of the new secure connection details.
  11. Run 'kubectl get nodes' on the control-plane to see this node join the cluster.
复制代码
安装kubernets 网络插件 calico(master节点操作)

安装包在 准备文件的 k8s/calico.yaml下,上传到服务器/home 下
下载 calico文档 https://docs.projectcalico.org/manifests/calico.yaml
修改文件中的镜像地址
  
  1. grep image calico.yaml
  2. sed -i 's#docker.io/##g' calico.yaml
复制代码
  
  1. kubectl apply -f calico.yaml
复制代码
部署完成





免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4