drone.yaml
kind: pipeline
type: kubernetes
name: default
clone:
disable: true
workspace:
path: /go/gks
steps:
- name: clone
image: alpine/git
volumes:
- name: gopath
path: /go
commands:
- cd ../
- echo '192.168.2.106 gogs.kakj.com' >> /etc/hosts
- git clone http://gogs.kakj.com/kakj/gks.git
- name: info
image: everpeace/curl-jq
commands:
- "curl -o info_drone -x 192.168.2.106:80 http://drone.kak.com/api/repos/kakj/gks/builds -H 'Authorization: Bearer 0C5mC1JNBW91qyNcW7ZbtY4AWs8FRAuh'"
- jq '.[0].number' info_drone > .tags
- name: build
image: golang
commands:
- go env -w GOPROXY=https://goproxy.cn,direct
- go mod tidy
- go test
- go build -o gks
- name: docker
image: plugins/docker
settings:
repo: kakj/gks
username:
password:
dockerfile: dockerfile
# tags: ${DRONE_BUILD_NUMBER}
- name: deploy-config
image: danielgormly/drone-plugin-kube:0.0.1
settings:
template: container/configmap.yaml
configmap_file: container/config.yaml
ca:
server: https://192.168.2.101:6443
token:
- name: deploy-deployment
image: danielgormly/drone-plugin-kube:0.0.1
settings:
build_number: ${DRONE_BUILD_NUMBER}
template: container/deployment.yaml
ca:
server: https://192.168.2.101:6443
token:
volumes:
- name: gopath
temp: {}
trigger:
branch:
- master
说明
- 由于我这边Host不能映射,所以这边的git clone是自定义的,所以要配置host映射
- k8s的drone workspace需要设置要不然不会自动再项目的目录下,然后clone要在volumn挂载下 ../,这样其他步骤才能在项目目录下
- info是获取drone的信息的,为了下面自动化的时候能根据drone的信息进行构建,不如docker的tag
- plugins类型的步骤只要文档上没说明commomd就不能使用,使用了会覆盖plugins的功能
- k8s连接的ca直接查看kubectl的
vi /etc/kubernetes/admin.conf - token根据下面yaml进行创建和获取
- k8s的template是configmap类型的时候强制要使用configmap_file,所以只能文件进行映射,多个文件还没试过
k8s.yaml
kubectl describe secret | grep -A 10 admin-user
apiVersion: v1
kind: ServiceAccount
metadata:
name: admin-user
namespace: default
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: admin-user
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: admin-user
namespace: default