您现在的位置是:挑肥拣瘦网 > 热点
如何快速搭建Kubernetes实验环境?
挑肥拣瘦网2026-11-14【热点】{固定数字1}人已围观
简介谷歌霸屏技术【tg:seogoogle987】
很多小伙伴想学kubernetes,都会遇到这些问题
手里没有可用的服务器 打开kubernetes官方文档,看到复杂的组件学不下去
今天就介绍一种省钱省时的方式来玩kubernetes
准备服务器
很多小伙伴电脑配置比较高,可以直接用虚拟机开两台机器,至少得确保自己的电脑16G内存以上
我一个穷鬼,用着8G内存小本,没办法,我选择云服务器
在阿里云平台充值100块,选择按量付费,每小时3毛钱的2c4G突发性能实例,玩一晚上也就一罐红牛的价格
服务器开好就可以开始部署kubernetes了,本文采用kubeadm方式快速搭建kubernetes集群
修改系统参数 加载br_netfilter模块 查看是否加载br_netfilter lsmod | grep br_netfilter 加载br_netfilter 如何;modprobe br_netfilter 或者修改module-load文件 cat <> /etc/hosts << EOF 192.168.4.34 k8s-master 192.168.4.35 k8s-node01 EOF 设置时钟同步,用ntpdate或chronyd yum -y install epel-release chrony && systemctl enable chronyd && systemctl start chronyd 安装快速docker # 配置docker-ce的yum源 wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo # 安装docker-ce yum -y install docker-ce # 设置开机自启动并启动docker systemctl enable docker && systemctl start docker # 查看docker版本 docker vers搭建ion 配置kubernetes的yum源 cat > /etc/yum.repos.d/kubernetes.repo << EOF [kubernetes] name=Kubernetes baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64 enabled=1 gpgcheck=0 repo_gpgcheck=0 gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/Kuyum/doc/rpm-package-key.gpg EOF 安装kubeadm、kubelet、kubectl yum -y install kubeadm kubelet kubectl systemctl enable kubelet
kubelet是kubernetes项目用来操作Docker等容器运行时的核心组件,在每个节点上都存在,可以说除了跟容器运行时打交道外,kubelet在配置容器网络、管理容器数据卷时,他都需要直接操作宿主机
如果kubelet本身就是运行在一个容器里,那么直接操作宿主机就会变的很麻烦,所以为了解决这个问题,kubeadm选择直接将kubelet部署在宿主机上,然后使用容器部署其他组件
部署kubernetes Masterbe kubeadm init --apiserver-advertise-address=172.22.29.78 --image-repository registry.aliyuncs.com/google_containers --kubernetes-version v1.21.2 --service-cidr=10.1.0.0/16 --pod-network-cidr=10.244.0.0/16
提示coredns:v1.8.0不存在,解决办法:
# 添加docker加速器 tee /etc/docker/daemon.json <<-'EOF' rn123; "registry-mirrors": ["https://fl791z1h.mirror.aliyuncs.com"] } EOF systemctl daemon-reload systemctl restart docker # 手动下载coredns镜像 docker pull coredns/coredns:1.8.0 # 修改镜像tag docker tag coredns/coredns:1.8.0 registry.aliyuncs.com/google_containers/coredns:v1.8.0
之后再重新et初始化
最后生成的join部分是节点加入集群的命令
根据提示操作,创建kubectl mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config 设置kubectl自动补充 source <(kubectl completion bash)
默认token有效期24小时,过期后token不可用,如果后续有node加入,解决方法是重新生成token
kubeadm token create&esnbsp; 查看token kubeadm token list
查看pod kubectl get pod --all-namespaces
可以看到coredns的pod没有启动,是pending状态,node节点为NotReady,缺少网络pod
node加入集群 kubeadm join 172.22.29.78:6443 --token gtj686.cu5kxoxbgq8iha4m --discovery-token-ca-cert-hash sha256:e6aa8e197b74a08d9bae4b5d72854a499805实验39bc504691440fe5d716a3d299d9
查看node
安装网络,这里选择calico
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
安装后查看pod状态
从下载镜像到初始化到running状态
calico网络安装的时候,其中有一个pod一直是imagepullbackoff状态
后来发现是因为node没有做镜像仓库加速处理,所以镜像下载失败,导致pod状态一直是imagepullbackoff状态
配置完成后,Pod自动下载镜像,所有pod都running状态
查看node节点的images
至此kubernetes集群部署完毕
测试kubernetes
在集群中创建一个pod,对外暴露端口,验证是否正常访问
# 创建一个环境nginx的deployment kubectl create deployment nginx --image=nginx # 对外暴露端口 kubectl expose deployment nginx --port=80 --type=NodePort # 查看pod和svc kubectl get pod,svc
可以看到nginx的pod映射到宿主机端口为30830,安全组和防火墙开放的情况下尝试访问
部署dashboard # 下载dashboard编排文件 wget https://raw.githubusercontent.com/如何kubernetes/dashboard/v2.0.0-rc7/aio/deploy/recommended.yaml # 以该编排文件创建pod kubectl create -f recommended.yaml # 查看创建好的pod和svc kubectl get pod,svc -n kubernetes-dashboard
这里改了recommended.yaml里面,kubernetes-dashboard的端口类型为nodeport,并对外暴露30000
访问提示两种登录方式,这里用token登录
# 获取token kubectl describe secrets 快速-n kubernetes-dashboard
复制token然后登录
提示没有权限,重新创建
# 创建sa,并绑定cluster-admin权限 apiVersion: v1 kind: ServiceAccount metadata: name: dashboard-admin namespace: kube-system --- kind: ClusterRoleBinding apiVersion: rbac.authorization.k8s.io/v1beta1 metadata: name: d搭建ashboard-admin subjects: - kind: ServiceAccount name: dashboard-admin namespace: kube-system roleRef: kind: ClusterRole name: cluster-admin apiGroup: rbac.authorization.k8s.io # 将上面的编排文件保存为k8s-admin.Kuyaml,然后创建 kubectl create -f k8s-admin.yaml
重新获取token,重新登录
kubectl describe secret -n kube-system
创建用户的时候,这里走进误区了,刚开始一直创建的是在kubernetes-dashboard的namespaces,其实这个namespaces下什么权限都没有,所以它创建的user的token是获取不到任何内容的
修改了yaml,重新创建sa之后,在kube-system中找到dashboard-admin用户的token,重新登录后,一切ok
很赞哦!(489746)
站长推荐
友情链接
- 标签: 康师傅
- https://blvdseafood.com/?s=谷歌霸屏技术【tg:seogoogle987】wMm
- https://www.smarty.net/search?q=谷歌霸屏技术【tg:seogoogle987】,UIo
- https://www.teamlab.art/zh-hans/?submit=谷歌霸屏技术【tg:seogoogle987】,jzv
- https://www.lyrics.com/lyrics/谷歌霸屏技术【tg:seogoogle987】,aq1
- https://www.silentiumpc.com/en/search/谷歌霸屏技术【tg:seogoogle987】,jTB
- https://www.riohondo.edu/?action=QUERY&s=谷歌霸屏技术【tg:seogoogle987】,T6b
- https://www.reginatangoshoes.com/en/catalogsearch/result/index/?T=1686132113407&q=谷歌霸屏技术【tg:seogoogle987】,MEw
- https://5gaa.org/?token=6e2l7hjt2i26gzgctgwdrv7v0j6nxorq&s=谷歌霸屏技术【tg:seogoogle987】CNS
- https://www.schenckprocess.com/search?q=谷歌霸屏技术【tg:seogoogle987】,B9n
- https://www.tarleton.edu/?s=谷歌霸屏技术【tg:seogoogle987】,Otq
- https://www.routesonline.com/search/?query=谷歌霸屏技术【tg:seogoogle987】,fU7
- https://www.kyuhoshi.com/?s=谷歌霸屏技术【tg:seogoogle987】,G2m
- https://wwwcp.umes.edu/search/谷歌霸屏技术【tg:seogoogle987】,nGl
- https://www.spicebar.de/catalogsearch/result/?q=谷歌霸屏技术【tg:seogoogle987】,bdW
- https://www.youtube.com/hashtag/谷歌霸屏技术【tg:seogoogle987】,FFp
- https://www.hanbat.ac.kr/search/front/Search.jsp?qt=谷歌霸屏技术【tg:seogoogle987】EDR
- https://www.so.com/s?ie=utf-8&src=360sou_home&_re=0&q=谷歌霸屏技术【tg:seogoogle987】,klM
- https://www.xvideos.com/tags/谷歌霸屏技术【tg:seogoogle987】,SuJ
- https://www.pmindia.gov.in/en/?s=谷歌霸屏技术【tg:seogoogle987】,ikO
- https://www.sonepar.ch/fr/search?q=谷歌霸屏技术【tg:seogoogle987】,FhY
- https://www.klatreverden.no/search?q=谷歌霸屏技术【tg:seogoogle987】,6mX
- https://www.maine.gov/pfr/professionallicensing/search/node?keys=谷歌霸屏技术【tg:seogoogle987】,mR7
- https://xehay.vn/tim-kiem/=谷歌霸屏技术【tg:seogoogle987】,WRM
- https://www.maafushidive.com?collections?vendors?q=谷歌霸屏技术【tg:seogoogle987】,wcT
- https://www.navylookout.com/?ID=nSBR6Ivdu6lZg1yr2SDs30Lo5sTs76yJ&s=谷歌霸屏技术【tg:seogoogle987】,WaQ
- https://www.kubb-tool.bfs.admin.ch/en/search?action=CHECK&q=谷歌霸屏技术【tg:seogoogle987】,Og4
- https://www.flickr.com/photos/tags/谷歌霸屏技术【tg:seogoogle987】JAd
- https://www.lyrics.com/lyrics/kkk3谷歌霸屏技术【tg:seogoogle987】,vDu
- https://www.tmtpost.com/search?q=谷歌霸屏技术【tg:seogoogle987】,qmv
- https://www.qwant.com/?q=谷歌霸屏技术【tg:seogoogle987】,2wy
- https://www.jusoen.com/addreng.asp?p1=谷歌霸屏技术【tg:seogoogle987】yMx
- https://www.wou.edu.my/?s=谷歌霸屏技术【tg:seogoogle987】,bto
- https://www.nctsn.org/search?cat=191&query=谷歌霸屏技术【tg:seogoogle987】,IVZ
- https://www.laoairlines.com/?action=QUERY&s=谷歌霸屏技术【tg:seogoogle987】,oat
- https://www.remit.co.jp/vi/?s=谷歌霸屏技术【tg:seogoogle987】p68
- https://www.wikiart.org/pt/Search/谷歌霸屏技术【tg:seogoogle987】,yvy
- https://www.posten-portal.de/search?query=谷歌霸屏技术【tg:seogoogle987】,PcP
- https://www.paulaschoice.hk/zh_hant/catalogsearch/result/?q=谷歌霸屏技术【tg:seogoogle987】,SZX
- https://www.merchbar.com/search?q=谷歌霸屏技术【tg:seogoogle987】,ZAE
- https://www.remit.co.jp/zh/?s=谷歌霸屏技术【tg:seogoogle987】,q8V
- https://www.qylaws.com/search/谷歌霸屏技术【tg:seogoogle987】,ZbA
- https://www.remit.co.jp/pt/?action=CHECK&s=谷歌霸屏技术【tg:seogoogle987】,VEy
- https://www.youtube.com/results?search_query=谷歌霸屏技术【tg:seogoogle987】,sOR
- https://blvdseafood.com/?s=谷歌霸屏技术【tg:seogoogle987】VxT
- https://www.unclefossil.com/search/谷歌霸屏技术【tg:seogoogle987】gad_source=1&gclid=Cj0KCQjw_-GxBhC1ARIsADGgDjsNKplUXa2F6YGlHBK2sHDQ88cgsJBb05DyO99TV9jNq_cT0kGMqyQaAgHQEALw_wcB
- https://www.pierreherme.com/catalogsearch/result/?q=谷歌霸屏技术【tg:seogoogle987】,7pN
- https://www.remit.co.jp/id/?s=谷歌霸屏技术【tg:seogoogle987】,ZcC
- https://jihoon471.cafe24.com/product/search.html?banner_action=&keyword=谷歌霸屏技术【tg:seogoogle987】Orl
- https://www.mdbg.net/chinese/dictionary?page=worddict&wdrst=0&wdqb=谷歌霸屏技术【tg:seogoogle987】,1DX
- https://www.scq.ubc.ca/?page=2&s=谷歌霸屏技术【tg:seogoogle987】,85A







