首页 > 系统相关 >国内 yum源安装 kubelet 和 kubeadm

国内 yum源安装 kubelet 和 kubeadm

时间:2023-11-17 17:13:10浏览次数:41  
标签:kubernetes -- kubelet token yum master kubeadm config

1.设置国内阿里源

cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

2.安装

yum install -y kubelet kubeadm kubectl 

3.需要安装指定版本,可以

yum install -y kubelet-1.23.4 kubeadm-1.23.4 kubectl-1.23.4
  1. 设置开机启动
systemctl enable kubelet && systemctl start kubelet

master 节点初始化

kubeadm config print init-defaults > kubeadm-config.yaml

编辑配置文件

vim kubeadm-config.yaml
apiVersion: kubeadm.k8s.io/v1beta3
bootstrapTokens:
- groups:
  - system:bootstrappers:kubeadm:default-node-token
  token: abcdef.0123456789abcdef
  ttl: 24h0m0s
  usages:
  - signing
  - authentication
kind: InitConfiguration
localAPIEndpoint:
  advertiseAddress: 192.168.xx.xx #修改成master节点IP
  bindPort: 6443
nodeRegistration:
  criSocket: /var/run/dockershim.sock
  imagePullPolicy: IfNotPresent
  name: k8s-master-1 #之前/etc/hosts里设置节点的别名
  taints: null
---
apiServer:
  timeoutForControlPlane: 4m0s
apiVersion: kubeadm.k8s.io/v1beta3
certificatesDir: /etc/kubernetes/pki
clusterName: kubernetes
controllerManager: {}
dns: {}
etcd:
  local:
    dataDir: /var/lib/etcd
imageRepository: registry.aliyuncs.com/google_containers #改成国内源
kind: ClusterConfiguration
kubernetesVersion: 1.23.0
networking:
  dnsDomain: cluster.local
  serviceSubnet: 10.96.0.0/12
  podSubnet: 10.244.0.0/16
scheduler: {}

预先拉取所需镜像

kubeadm config images pull --config=kubeadm-config.yaml

初始化
加上 tee kubeadm-init.log,方便后续查看 token 和初始化信息

 kubeadm init --config=kubeadm-config.yaml | tee kubeadm-init.log

成功信息

[addons] Applied essential addon: kube-proxy

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 192.168.31.170:6443 --token abcdef.0123456789abcdef \
        --discovery-token-ca-cert-hash sha256:a5d9c8d271fc1b3165fa8bbdcc9b092207a223509b8ae53aa0078d13f67b050f 

按照提示,root 身份简单设置

echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile
#启动生效
source ~/.bash_profile

master节点安装pod网络

curl  -o  kube-flannel.yml  https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
#把yml文件中的所有的quay.io改为quay.mirrors.ustc.edu.cn 
sed  -i  's/quay.io/quay.mirrors.ustc.edu.cn/g'   kube-flannel.yml
#生成 flannel 插件pod
kubectl apply -f kube-flannel.yml
#确认所有的Pod都处于Running状态
kubectl get pod -n kube-system

添加worker节点

#每一个节点服务器也和 master 主节点一样安装 Docker、kubectl、kubelet和kubeadm
#如果master 重新init,则work节点join之前先执行 kubeadm reset
#按照 master 初始化的输出提示加入集群
kubeadm join 192.168.31.170:6443 --token abcdef.0123456789abcdef \
        --discovery-token-ca-cert-hash sha256:a5d9c8d271fc1b3165fa8bbdcc9b092207a223509b8ae53aa0078d13f67b050f

#如果没有记住刚才的 token , master 主机  # cat kubeadm-init.log 可以找到,或这样

 kubeadm token list

#如果超过 24 小时没有 join ,token 过期,需要在 master 重新获取 token

kubeadm token create 8mfiss.yvbnl8m319ysiflh

#获取ca证书sha256编码hash值

openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //'

#节点加入集群

 kubeadm join --token aa78f6.8b4cafc8ed26c34f --discovery-token-ca-cert-hash sha256:0fd95a9bc67a7bf0ef42da968a0d55d92e52898ec37c971bd77ee501d845b538  192.168.x.x:6443 --skip-preflight-checks

#验证node和 Pod状态,

kubectl get nodes

kubectl get pods --all-namespaces


标签:kubernetes,--,kubelet,token,yum,master,kubeadm,config
From: https://www.cnblogs.com/flyhgx/p/17839199.html

相关文章

  • 使用reposync工具将yum安装包保存到本地的方法
    使用reposync工具将yum安装包保存到本地的方法版权声明:原创作品,谢绝转载!否则将追究法律责任。—————作者:kirin1、修改yum配置#修改配置文件[root@kirin365data]#vim/etc/yum.confcachedir=/usr/local/cache#包保存的路径keepcache=1#1为保存0为不保存2、reposy......
  • yum 只下载不安装
    yuminstall--downloadonly--downloaddir=./postgresql12-server 在使用yum包管理器时,可以通过添加--downloadonly参数来实现只下载软件包而不安装。要只下载软件包而不进行安装,可以使用以下命令:bash复制代码yuminstall--downloadonly<package_name>将<package......
  • k8s中,如何通过token的方式,访问认证的kubelet的metrics指标?
     1、背景说明kubelet本身的10250端口,就提供了节点上的监控数据。 metricsserver可以进行访问。 但是,如果想要通过浏览器,或者curl命令进行访问,发现,是需要进行认证  [root@nccztsjb-node-02~]#curl-khttps://172.20.59.238:10250/metricsUnauthorized[root@n......
  • k8s之集群部署(kubeadm)
     [master&node]1.修改主机名hostnamectlset-hostnamemaster-01cat>>/etc/hosts<<EOF172.28.32.1master-01172.28.32.2worker-01EOF 2.配置阿里云官方源mkdir-p/etc/yum.repos.d/backfind/etc/yum.repos.d/-typef-execmv{}/etc/yum.repos.d/back......
  • Yum工具
    linux常见的基础依赖环境,一般这些软件应该是在系统安装时,勾选上,如果没有则需要手动安装yuminstallgccpatchlibffi-develpython-devel zlib-develbzip2-developenssl-develncurses-develsqlite-develreadline-develtk-develgdbm-develdb4-devellibpcap-develxz-dev......
  • 使用 kubeadm 进行证书管理
    检查证书是否过期kubeadmcertscheck-expiration[check-expiration]Readingconfigurationfromthecluster...[check-expiration]FYI:Youcanlookatthisconfigfilewith'kubectl-nkube-systemgetcmkubeadm-config-oyaml'CERTIFICATE......
  • centos7安装nfs(离线和yum都可以)
    一:检查端口是否占用本程序占用2049的tcp和udp端口;二:安装nfs:yum安装:yuminstallnfs-utilsrpcbind-y注意:服务端和客户端都是这个命令离线包安装:百度网盘下载安装包:链接:https://pan.baidu.com/s/1ORc1cXa042tP5DDRJgbuXw?pwd=1234提取码:1234下载上述nfs离线包,把包上传......
  • kubeadm 参数说明
    kubeadm使用帮助kubeadm-h┌──────────────────────────────────────────────────────────┐│KUBEADM││EasilybootstrapasecureKube......
  • kubeadm部署的k8s证书过期问题 k8s问题排查:the existing bootstrap client certifica
     解决问题:估计跟移动有关,下面那个没解决问题,是因为在原有文件的基础上修改的吧?而这里直接是移走,重新生成了新的。不太清楚是不是这个原因。$cd/etc/kubernetes/pki/$mv{apiserver.crt,apiserver-etcd-client.key,apiserver-kubelet-client.crt,front-proxy-ca.crt,front......
  • yum源修改基于CentOS Linux release 8.3.2011
    查看系统版本:(8的镜像源都可以用不用分小版本)cat/etc/redhat-release修改centos文件内容sed-i's/mirrorlist/#mirrorlist/g'/etc/yum.repos.d/CentOS-*sed-i's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g'/etc/yum.repos.d/CentOS......