前言:自定义项目参考【Docker】Dockerfile构建自定义进阶的helloworld镜像-2和【Docker】将自定义的镜像上传至dockerhub或阿里云私有仓库,并在其他节点进行拉取。

0 将集群启动

# 关闭防火墙
root@master:/home/hqc/k8s_test/array-plus# ufw disable防火墙在系统启动时自动禁用# 禁用分区
root@master:/home/hqc/k8s_test/array-plus# swapoff -a# 查看状态
root@master:/home/hqc/k8s_test/array-plus# kubectl get nodesNAME     STATUS     ROLES    AGE   VERSIONmaster   Ready      master   25d   v1.18.0node01   Ready      <none>   20d   v1.18.0

1 yaml文件创建deployment

尝试自动创建:报错

root@master:/home/hqc/k8s_test/array-plus# kubectl create deployment array-plus-deployment --image=registry.cn-beijing.aliyuncs.com/hqc-k8s/ali-array-plus:v2.5  --dry-run -o yml > array-plus-deployment.ymalW1213 20:50:23.489941    1289 helpers.go:535] --dry-run is deprecated and can be replaced with --dry-run=client.error: unable to match a printer suitable for the output format "yml", allowed formats are: go-template,go-template-file,json,jsonpath,jsonpath-file,name,template,templatefile,yaml
# 自动创建的方法不对,启用

直接创建:

# 编写
root@master:/home/hqc/k8s_test/array-plus# vim array-plus-deployment.yamlapiVersion: apps/v1
kind: Deployment
metadata:creationTimestamp: nulllabels:app: array-plus-deploymentname: array-plus-deployment
spec:replicas: 2selector:matchLabels:app: array-plus-deploymentstrategy: {}template:metadata:creationTimestamp: nulllabels:app: array-plus-deploymentspec:containers:- image: registry.cn-beijing.aliyuncs.com/hqc-k8s/ali-array-plus:v2.5name: ali-array-plusresources: {}ports:- containerPort: 5000imagePullPolicy: IfNotPresent
status: {}# 创建
root@master:/home/hqc/k8s_test/array-plus# kubectl create -f array-plus-deployment.yaml
deployment.apps/array-plus-deployment created
# 成功

2 yaml文件创建service

# 编写
root@master:/home/hqc/k8s_test/array-plus# vim array-plus-service.yamlapiVersion: v1 # 注意此处不能和deployment一样为‘apps/v1’
kind: Service
metadata:name: array-plus-deploymentlabels:app: array-plus-deployment
spec:ports:- port: 80targetPort: 5000nodePort: 30000protocol: TCPselector:app: array-plus-deploymenttype: NodePort# 创建
root@master:/home/hqc/k8s_test/array-plus# kubectl create -f array-plus-service.yaml service/array-plus-deployment created
# 成功

3 查看

root@master:/home/hqc/k8s_test/array-plus# kubectl get allNAME                                         READY   STATUS         RESTARTS   AGEpod/array-plus-deployment-55657b7c55-wfjtx   0/1     ErrImagePull   0          6m33spod/array-plus-deployment-55657b7c55-z8kx2   0/1     ErrImagePull   0          6m33spod/helloworld-deployment-79cbf4dcbb-5x6b2   1/1     Running        1          12dpod/helloworld-deployment-79cbf4dcbb-n5sps   1/1     Running        1          12dpod/helloworld-deployment-79cbf4dcbb-sr8xf   1/1     Running        1          12dpod/helloworld-deployment-79cbf4dcbb-wfh5w   1/1     Terminating    0          12dpod/nginx-f89759699-ksgcb                    1/1     Running        2          13dNAME                            TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGEservice/array-plus-deployment   NodePort    10.102.249.251   <none>        80:30000/TCP   93sservice/helloworld-deployment   NodePort    10.106.97.144    <none>        80:30002/TCP   13dservice/kubernetes              ClusterIP   10.96.0.1        <none>        443/TCP        25dservice/nginx                   NodePort    10.109.178.122   <none>        80:30650/TCP   13dNAME                                    READY   UP-TO-DATE   AVAILABLE   AGEdeployment.apps/array-plus-deployment   0/2     2            0           6m33sdeployment.apps/helloworld-deployment   3/3     3            3           12ddeployment.apps/nginx                   1/1     1            1           13dNAME                                               DESIRED   CURRENT   READY   AGEreplicaset.apps/array-plus-deployment-55657b7c55   2         2         0       6m33sreplicaset.apps/helloworld-deployment-79cbf4dcbb   3         3         3       12dreplicaset.apps/nginx-f89759699                    1         1         1       13d
# 发现并未成功

4 问题解决

结合之前的实践经验,问题应该出在节点上没法实时进行拉取,需要在各节点上事先拉取好才行。

# 登录镜像仓库
root@nodroot@node01:/hroot@nrootrootrorororoot@node01:/home/user# docker login --username=errorhqc兮 registry.cn-beijing.aliyuncs.comPassword: WARNING! Your password will be stored unencrypted in /root/.docker/config.json.Configure a credential helper to remove this warning. Seehttps://docs.docker.com/engine/reference/commandline/login/#credentials-storeLogin Succeeded# node本地拉取镜像
root@node01:/home/user# docker pull registry.cn-beijing.aliyuncs.com/hqc-k8s/ali-array-plus:v2.5v2.5: Pulling from hqc-k8s/ali-array-plus647acf3d48c2: Already exists b02967ef0034: Already exists e1ad2231829e: Already exists 5576ce26bf1d: Already exists a66b7f31b095: Already exists 05189b5b2762: Already exists af08e8fda0d6: Already exists 287d56f7527b: Already exists dc0580965fb6: Already exists 1cb8e8d308bd: Pull complete c68499244bc4: Pull complete 1dafd85198a4: Pull complete Digest: sha256:1dd85ae174eeedbaa5d370e625c6db439c4188634e58d648a6b5d30e28b9aa86Status: Downloaded newer image for registry.cn-beijing.aliyuncs.com/hqc-k8s/ali-array-plus:v2.5registry.cn-beijing.aliyuncs.com/hqc-k8s/ali-array-plus:v2.5# 查看镜像
root@node01:/home/user# docker imagesREPOSITORY                                                       TAG       IMAGE ID       CREATED         SIZEregistry.cn-beijing.aliyuncs.com/hqc-k8s/ali-array-plus          v2.5      7f4f56bbf3c8   2 hours ago     928MB

master中再次查看:发现包括service全部正常

root@master:/home/hqc/k8s_test/array-plus# kubectl get allNAME                                         READY   STATUS        RESTARTS   AGEpod/array-plus-deployment-55657b7c55-wfjtx   1/1     Running       0          10mpod/array-plus-deployment-55657b7c55-z8kx2   1/1     Running       0          10mpod/helloworld-deployment-79cbf4dcbb-5x6b2   1/1     Running       1          12dpod/helloworld-deployment-79cbf4dcbb-n5sps   1/1     Running       1          12dpod/helloworld-deployment-79cbf4dcbb-sr8xf   1/1     Running       1          12dpod/helloworld-deployment-79cbf4dcbb-wfh5w   1/1     Terminating   0          12dpod/nginx-f89759699-ksgcb                    1/1     Running       2          13dNAME                            TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGEservice/array-plus-deployment   NodePort    10.102.249.251   <none>        80:30000/TCP   5m59sservice/helloworld-deployment   NodePort    10.106.97.144    <none>        80:30002/TCP   13dservice/kubernetes              ClusterIP   10.96.0.1        <none>        443/TCP        25dservice/nginx                   NodePort    10.109.178.122   <none>        80:30650/TCP   13dNAME                                    READY   UP-TO-DATE   AVAILABLE   AGEdeployment.apps/array-plus-deployment   2/2     2            2           10mdeployment.apps/helloworld-deployment   3/3     3            3           12ddeployment.apps/nginx                   1/1     1            1           13dNAME                                               DESIRED   CURRENT   READY   AGEreplicaset.apps/array-plus-deployment-55657b7c55   2         2         2       10mreplicaset.apps/helloworld-deployment-79cbf4dcbb   3         3         3       12dreplicaset.apps/nginx-f89759699                    1         1         1       13d

注意:无需将deployment和service删除重建,直接查看即可

5 运行验证

  1. master IP + port访问成功
  2. node IP + port访问成功
  3. dashboard中查看running成功

到此为止,完全成功!!!

【K8s】部署自定义项目到K8s集群上运行相关推荐

  1. 从认证到调度,K8s 集群上运行的小程序到底经历了什么?

    作者 | 声东  阿里云售后技术专家 导读:不知道大家有没有意识到一个现实:大部分时候,我们已经不像以前一样,通过命令行,或者可视窗口来使用一个系统了. 前言 现在我们上微博.或者网购,操作的其实不是 ...

  2. 在生产集群上运行topology

    2019独角兽企业重金招聘Python工程师标准>>> 在生产集群上运行topology 博客分类: 分布式计算 在生产集群上运行topology跟本地模式差不多.下面是步骤: 1) ...

  3. spark在集群上运行

    1.spark在集群上运行应用的详细过程 (1)用户通过spark-submit脚本提交应用 (2)spark-submit脚本启动驱动器程序,调用用户定义的main()方法 (3)驱动器程序与集群管 ...

  4. 如何在集群上运行Shark

    如何在集群上运行Shark 本文介绍在计算机集群上如何启动和运行Shark.如果对Amazon EC2上运行Shark感兴趣,请点击这里查看如何使用EC2脚本快速启动预先配置好的集群. 依赖: 注意: ...

  5. 小白学习Spark03-在集群上运行Spark

    03 在集群上运行Spark 3.1 Spark运行架构 3.1.1 驱动器节点 3.1.2 执行器节点 3.1.3 集群管理器 3.1.4 启动Spark程序 3.1.5 小结 3.2 使用spar ...

  6. pythonspark集群模式运行_有关python numpy pandas scipy 等 能在YARN集群上 运行PySpark

    有关这个问题,似乎这个在某些时候,用python写好,且spark没有响应的算法支持, 能否能在YARN集群上 运行PySpark方式, 将python分析程序提交上去? Spark Applicat ...

  7. 在local模式下的spark程序打包到集群上运行

    一.前期准备 前期的环境准备,在Linux系统下要有Hadoop系统,spark伪分布式或者分布式,具体的教程可以查阅我的这两篇博客: Hadoop2.0伪分布式平台环境搭建 Spark2.4.0伪分 ...

  8. anaconda3环境整体打包放在Spark集群上运行

    一.将虚拟Python环境打包 创建好环境后,进入到环境所在的文件夹,例如环境是/home/hadoop/anaconda3/envs, cd到envs下,使用打包命令将当前目录下的文件打成zip包: ...

  9. MapReduce作业在Hadoop完全分布式集群上运行的问题与思考(持续更新)

    1.集群已搭建好且通过了WordCount测试,但是在eclipse上开发的程序却仍然是只在namenode上运行 不知道是不是没有配置好eclipse上的Map/Reduce Locations,个 ...

最新文章

  1. 软件测试之功能测试详细过程
  2. jQuery如何动态删除TR,input按钮删除本行记录,checkbox全选反选
  3. Qt之QFutureWatcher
  4. 这款PDF阅读器1秒定位论文公式变量,不同页图文也能同屏看,刷论文再也不用来回翻页看文找图了! | 开源...
  5. Quartz教程二:API,Job和Trigger
  6. 农保和社保的区别有哪些
  7. 11.Pipelines
  8. python实现抢劵_用Python实现微信自动化抢红包,再也不用担心抢不到红包了
  9. 04_使用Influxdb自带函数查询
  10. matplotlib——在 Jupyter Notebook中绘制图像时只显示变量信息不显示图片
  11. 【JS】引用类型之RegExp
  12. OpenGL笔记5 shader 调试信息获取 Debug
  13. 电脑配置知识_电脑小知识:装机不求人!10 分钟电脑配置挑选速成攻略|硬盘|电脑|cpu|装机|固态硬盘|机械硬盘...
  14. CSS3特效----制作3D旋转导航
  15. Ant Design 框架
  16. 微信公众号迁移公证、迁移申请函办理方法
  17. Java程序员技术书籍指南
  18. python批量查询ip归属地_python查询ip归属地
  19. 电脑误格式化的数据怎么恢复,误格式化数据恢复教程
  20. sklearn中分割数据集的函数

热门文章

  1. (三)Position Rank代码解读(一)
  2. 中止执行后超过2年_执行期限过了两年怎么处理
  3. 取消usb计算机连接网络,usb连接(如何设置usb网络连接)
  4. python计算机视觉--全景图像拼接
  5. matlab查看hdf5数据,Matlab 操作 HDF5文件
  6. Redis 内存分析神器
  7. 计算机语言phal语言,2.7 PhalApi 2.x 国际化
  8. 推荐几个矢量图库网站
  9. Stronger Data Poisoning Attacks Break Data Sanitization Defenses
  10. L1-002打印沙漏C语言,沙漏