K8s and cicd--deploy drone to kubernetes for dynamic agent shrinkage

Source: Internet
Author: User
Tags sqlite database sqlite db k8s
This is a creation in Article, where the information may have evolved or changed.

Objective

This article mainly discusses how to deploy drone to the k8s cluster, itself drone this container-based pipeline approach, and k8s is quite fit. The benefits are:

    • k8s cluster daemon Drone-server and drone-agent.
    • RPC features can be leveraged to dynamically adjust the number of agents according to the agent load pressure. Of course, even if we do not dynamically adjust, we manually adjust the number of copies of the set is quite simple.
    • After deploying to the k8s cluster, you can take advantage of K8s's existing log system and monitoring system.

In fact, in the next article series, we will continue to focus on k8s-related. Still is directly first on the Yaml file, first come to an intuitive feeling.

Related YAML file

Configmap can be understood here as a configuration file for drone applications. Here are a series of settings for the server and agent. However, in k8s, it is important to note that: after updating Configmap, the configuration will not take effect immediately for applications that mount the Configmap, and it will take approximately 10s.

apiVersion: v1kind: ConfigMapmetadata:  name: drone-config  namespace: devopsdata:  #######################  # Drone Server Config #  #######################  # server host name  server.host: drone.xxx.com  # start the server in debug mode  server.debug: "false"  # open user registration  server.open: "true"  # database driver, defaul as sqlite3  server.database.driver: sqlite3  # database driver configuration string  server.database.datasource: drone.sqlite  # remote parameters (Gogs)  server.remote.gogs: "true"  server.remote.gogs.url: "http://gogs.xxx.com"  server.remote.gogs.private.mode: "true"  ######################  # Drone Agent Config #  ######################  agent.debug: "false"  agent.debug.pretty: "false"  agent.max.procs: "1"  agent.healthcheck: "true"

Secret files, mainly storing some secret keys and the like. But there is also a pit here, this secret is used for server and angent communication, the setup is not built the project has been in pending state. Remember K8s,secret need base64.

echo -n "yourpassword" | base64eW91cnBhc3N3b3Jk
apiVersion: v1kind: Secretmetadata:  name: drone-secrets  namespace: devopsdata:  server.secret: eW91cnBhc3N3b3Jk

The next step is Drone-server's deployment and service and ingress. Here for the sake of simplicity, with the SQLite database, the real production environment is recommended for MySQL or pgsql. Even with SQLite, it should be mounted to ceph to ensure data security. Here directly Hostpath. In k8s, the separation of storage and computation should be done.

Apiversion:extensions/v1beta1kind:deploymentmetadata:name:drone-server namespace:devopsspec:replicas:1 Template : Metadata:labels:app:drone-server spec:nodeselector:net-type:external containers :-Image:drone/drone:latest Imagepullpolicy:always name:drone-server ports:-Contain erport:8000 protocol:tcp-containerport:9000 protocol:tcp volumemounts: # Pe        Rsist our configs in a SQLite DB in here-name:drone-server-sqlite-db mountpath:/var/lib/drone          resources:requests:cpu:40m memory:32mi env:-Name:drone_host Valuefrom:configmapkeyref:name:drone-config Key:server.host-name:dro        Ne_open Valuefrom:configmapkeyref:name:drone-config Key:server.open -Name:drone_databasE_driver Valuefrom:configmapkeyref:name:drone-config Key:server.database . Driver-name:drone_database_datasource valuefrom:configmapkeyref:name:drone- Config Key:server.database.datasource-name:drone_secret Valuefrom:secretkeyre            F:name:drone-secrets key:server.secret-name:drone_gogs Valuefrom:          Configmapkeyref:name:drone-config Key:server.remote.gogs-name:drone_gogs_url        Valuefrom:configmapkeyref:name:drone-config Key:server.remote.gogs.url              -Name:drone_gogs_private_mode Valuefrom:configmapkeyref:name:drone-config              Key:server.remote.gogs.private.mode-name:drone_debug Valuefrom:configmapkeyref: Name:drone-conFig key:server.debug Volumes:-Name:drone-server-sqlite-db Hostpath:path: /var/lib/drone
apiVersion: v1kind: Servicemetadata:  name: drone-service  namespace: devopsspec:  ports:  - name: http    protocol: TCP    port: 80    targetPort: 8000  - name: grpc    protocol: TCP    port: 9000    targetPort: 9000  selector:    app: drone-server
apiVersion: extensions/v1beta1kind: Ingressmetadata:  name: drone-ingress  namespace: devopsspec:  rules:  - host: drone.xxx.com    http:      paths:      - backend:          serviceName: drone-service          servicePort: 80        path: /

The following is the agent's deployment file, replicas:1 This item can set the number of agents, expansion is particularly convenient. The server and agent communicate through GRPC, the primary port is 9000.

Apiversion:extensions/v1beta1kind:deploymentmetadata:name:drone-agent namespace:devopsspec:replicas:1 Template:      Metadata:labels:app:drone-agent spec:nodeselector:net-type:external Containers: -Image:drone/agent:latest imagepullpolicy:always name:drone-agent volumemounts: # E          Nables Docker in Docker-name:docker-socket mountpath:/var/run/docker.sock resources: requests:cpu:100m memory:64mi LivenessProbe:httpGet:path:/health          Z port:3000 initialdelayseconds:3 periodseconds:3 env:-Name:drone_server value:drone-service:9000 # Issue:https://github.com/drone/drone/issues/2048-name:docker_api_ve Rsion value: "1.24"-Name:drone_secret valuefrom:secretkeyref:name:d            Rone-secrets  Key:server.secret volumes:-Name:docker-socket Hostpath:path:/var/run/docker.sock 

All deployed under the DevOps namespace, this namespace has been built. Of course, if not, you need to create them in advance.

Summarize

Project GitHub address, where all the files for the series are available.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.