Skip to content

mamezou-tech/concourse-k8s-resource

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

concourse-k8s-resource

Go Report Card Github Action

Concourse CI custom resource for kubernetes.

This resource assumes that kubernetes deployment is executed by plain manifests(kubectl apply -f) or Kustomize(kubectl apply -k).

In addition to deploy(kubectl apply) operation, it also supports delete(kubectl delete) and undo(kubectl rollout undo) operations.

This resource has been tested on kubernetes v1.20.1 and concourse v6.7.2.

Source Configuration

  • api_server_url - Kubernetes API Server URL. (e.g. https://172.16.10.11:6443)
  • api_server_cert - Kubernetes api server certificate.
  • client_cert - Client certificate that authenticated to access cluster, if specified, clusterKey is required.
  • client_key - Client key corresponding to client_cert.
  • client_token - Kubernetes ServiceAccount token. Required when accessing a cluster with ServiceAccount(neither client_cert nor client_key).
  • kubeconfig - Contents of kubecofig(YAML). if specified, other auth settings(including api_server_url) are ignored.
  • skip_tls_verify - true if you want to skip TLS verification.
  • namespace - Name of target kubernetes namespace. if not specified, default is used.

Behavior

check

Triggers when the watched resources is updated. The Revision consists of namespace, resource name, and revision(Deployment or StatefulSet resource). Multiple resources are combined with +.

Example version format : dev:app1:100+dev:app2:50+dev:app3:10.

in

Retrieves the watched resource's version and writes to version file.

out

Deploys the watched resources to kubernetes using plain manifests or Kustomize overlays. After deployed, wait for the specified time to complete.

  • paths - kubernetes manifest paths(array). plain manifests path(e.g. k8s/deployment.yaml) or kustomize directory(e.g. repo/overlays/prod)
  • kustomize - true if deploying by kustomize. Default to false.
  • status_check_timeout - The time(seconds) to wait for deployment to complete. Default to 5 minutes.
  • command_timeout - The time(seconds) to wait for kubectl apply or delete. Default to unlimited(0).
  • diff - true if using kubectl diff. Default to false.
  • server_dry_run - true if using kubectl apply --dry-run=server. Default to false.
  • delete - true if using kubectl delete operation. Default to false.
  • undo - true if using kubectl rollout undo operation(target resources are watchedResources). Default to false.

Example

See full configuration example here.

resource_types

resource_types:
- name: k8s
  type: docker-image
  source:
    repository: kudohn/concourse-k8s-resource
    tag: 0.0.8

resources

resources:
- name: k8s
  type: k8s
  source:

    api_server_url: https://172.16.10.11:6443
    api_server_cert: |
      -----BEGIN CERTIFICATE-----
      ....
      -----END CERTIFICATE-----
    # use client certificate
    client_cert: |
      -----BEGIN CERTIFICATE-----
      ...
      -----END CERTIFICATE-----
    client_key: |
      -----BEGIN PRIVATE KEY-----
      ...
      -----END PRIVATE KEY-----

    # or use service account token
    client_token: ....

    # or use kubeconfig
    kubeconfig: |
      apiVersion: v1
      kind: Config
      clusters:
        - cluster:
          ....
      contexts:
          ....
      current-context: ...
      users:
        - name: concourse
          user:
            ...

    skip_tls_verify: false
    namespace: dev
    # watched resources(deployment or statefulset is supported)
    watch_resources:
    - name: app1
      kind: Deployment
    - name: app2
      kind: Deployment
    - name: web
      kind: StatefulSet

put

Deploy resources using plain k8s manifests

jobs:
- name: deploy-app
  plan:
  - get: repo
  - put: k8s
    params:
      status_check_timeout: 60
      command_timeout: 30
      paths:
        - repo/test/plain/deploy1.yaml
        - repo/test/plain/deploy2.yaml
        - repo/test/plain/sts.yaml

Deploy resources using Kustomize manifests

jobs:
- name: deploy-app
  plan:
  - get: repo
  - put: k8s
    params:
      kustomize: true
      status_check_timeout: 60
      command_timeout: 30
      paths:
      - repo/test/kustomize/overlays/prod

Undo Resources

jobs:
- name: deploy-app
  plan:
  - get: repo
  - put: k8s
    params:
      undo: true

Deploy resources with server-dry-run

jobs:
- name: deploy-app
  plan:
  - get: repo
  - put: k8s
    params:
      paths:
      - repo/test/kustomize/overlays/prod
      server_dry_run: true

Diff Resources manifests

jobs:
- name: deploy-app
  plan:
  - get: repo
  - put: k8s
    params:
      paths:
      - repo/test/kustomize/overlays/prod
      diff: true

Delete Resources

jobs:
- name: deploy-app
  plan:
  - get: repo
  - put: k8s
    params:
      delete: true

License

MIT License