请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

老师我把drone 的构建换成 k8s了,但是构建的时候总是处于 loading...

我的需求是:
先不拉取代码,直接git 提交后,直接触发 k8s 的 yml 文件

是我哪里 对 drone 的理解错了吗????
.drone.yml

kind: pipeline
type: kubernetes
name: my-k8s

clone:
  disable: true 
steps:
- name: deploy
  image: bitnami/kubectl:latest
  volumes:
    - name: nginx-path
      path: /go/src/files
  commands:
  - rm -rf /root/.kube && cp -r .kube /root/.kube
  - cd /go/src/files
  - kubectl delete -f nginx.yml || true
  - kubectl apply -f nginx.yml

volumes:
  - name: nginx-path
    host:
      path: /go/src/files

我的宿主机 /go/src/files 事先已经 放了 .kube/config 文件 和 nginx.yml 文件
nginx.yml 文件

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deploymenet
  namespace: test
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx   #匹配  pod 标签 为 app: nginx 的 pod
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80 
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-sever
  namespace: test
spec:
  selector:  #选择器
    app: nginx
  type: NodePort
  ports:
  - port: 5000 
    targetPort: 80 
    nodePort: 33000

图片描述

[root@art files]# docker logs -f -n 30 drone-server
{"admin":true,"level":"info","login":"test12345","machine":false,"msg":"bootstrap: account created","time":"2023-11-04T17:10:56Z","token":"fyPUDkEdpgsILpbmnGSX2y1VaCrW3ThT"}
{"acme":false,"host":"192.168.2.115:9080","level":"info","msg":"starting the http server","port":":80","proto":"http","time":"2023-11-04T17:10:56Z","url":"http://192.168.2.115:9080"}
{"interval":"30m0s","level":"info","msg":"starting the cron scheduler","time":"2023-11-04T17:10:56Z"}
{"interval":"24h0m0s","level":"info","msg":"starting the zombie build reaper","time":"2023-11-04T17:10:56Z"}
[root@art files]# docker logs -f -n 30 drone-runner
time="2023-11-04T17:10:58Z" level=info msg="starting the server" addr=":3000"
time="2023-11-04T17:10:58Z" level=info msg="successfully pinged the remote server"
time="2023-11-04T17:10:58Z" level=info msg="polling the remote server" arch=amd64 capacity=2 endpoint="http://192.168.2.115:9080" kind=pipeline os=linux type=docker

正在回答 回答被采纳积分+3

1回答

暮闲 2023-11-05 15:45:36

同学你好,你用的drone-runner是哪个呢?如果你想直接在宿主机执行命令触发构建,推荐你用SSH Runner试试看呢,如图所示:

https://img1.sycdn.imooc.com/szimg/654747d2099ea5c719421296.jpg

这是drone ssh runner流水线的配置示例:

kind: pipeline
type: ssh
name: default

# 配置期望远程到哪台主机 去执行在steps定义的命令
server:
  host: 1.2.3.4
  user: root
  password:
   from_secret: password

steps:
- name: greeting
  commands:
    - echo hello world

来源:https://docs.drone.io/pipeline/ssh/overview/

你的报错一直处于loading状态,应该是没有安装kubernetes的runner,但是kubernetes的runner需要在集群内执行,所以直接使用ssh runner是更好的解决方式,这种方式也能兼容kubectl操作k8s集群。


0 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信