Using Webhooks Instead of Polling

By default, Fleet utilizes polling (default: every 15 seconds) to pull from a Git repo. This is a convenient default that works reasonably well for a small number of repos (up to a few tens).

For installations with multiple tens up to hundreds of Git repos, and in general to reduce latency (the time between a push to Git and fleet reacting to it), configuring webhooks is recommended instead of polling.

Fleet currently supports Azure DevOps, GitHub, GitLab, Bitbucket, Bitbucket Server, and Gogs.

1. Configure the webhook service. Fleet uses a gitjob service to handle webhook requests. Create an ingress that points to the gitjob service.

  1. apiVersion: networking.k8s.io/v1
  2. kind: Ingress
  3. metadata:
  4. name: webhook-ingress
  5. namespace: cattle-fleet-system
  6. spec:
  7. rules:
  8. - host: your.domain.com
  9. http:
  10. paths:
  11. - path: /
  12. pathType: Prefix
  13. backend:
  14. service:
  15. name: gitjob
  16. port:
  17. number: 80

If you want to have the webhook available using the same host name as your Rancher or another service, you can use the following YAML with the URL http://your.domain.com/gitjob. The below YAML is specific for the Nginx Ingress Controller:

  1. apiVersion: networking.k8s.io/v1
  2. kind: Ingress
  3. metadata:
  4. annotations:
  5. nginx.ingress.kubernetes.io/use-regex: "true"
  6. nginx.ingress.kubernetes.io/rewrite-target: /$2
  7. name: webhook-ingress
  8. namespace: cattle-fleet-system
  9. spec:
  10. rules:
  11. - host: your.domain.com
  12. http:
  13. paths:
  14. - path: /gitjob(/|$)(.*)
  15. pathType: ImplementationSpecific
  16. backend:
  17. service:
  18. name: gitjob
  19. port:
  20. number: 80

Using Webhooks Instead of Polling - 图1info

You can configure TLS on ingress.

2. Go to your webhook provider and configure the webhook callback url. Here is a Github example.

Using Webhooks Instead of Polling - 图2

Configuring a secret is optional. This is used to validate the webhook payload as the payload should not be trusted by default. If your webhook server is publicly accessible to the Internet, then it is recommended to configure the secret. If you do configure the secret, follow step 3.

Using Webhooks Instead of Polling - 图3note

only application/json is supported due to the limitation of webhook library.

Using Webhooks Instead of Polling - 图4caution

If you configured the webhook the polling interval will be automatically adjusted to 1 hour.

3. (Optional) Configure webhook secret. The secret is for validating webhook payload. Make sure to put it in a k8s secret called gitjob-webhook in cattle-fleet-system.

ProviderK8s Secret Key
GitHubgithub
GitLabgitlab
BitBucketbitbucket
BitBucketServerbitbucket-server
Gogsgogs
Azure DevOpsazure-username
Azure DevOpsazure-password

For example, to create a secret containing a GitHub secret to validate the webhook payload, run:

  1. kubectl create secret generic gitjob-webhook -n cattle-fleet-system --from-literal=github=webhooksecretvalue

For Azure DevOps:

  • Enable basic authentication in Azure
  • Create a secret containing the credentials for the basic authentication
  1. kubectl create secret generic gitjob-webhook -n cattle-fleet-system --from-literal=azure-username=user --from-literal=azure-password=pass123

4. Go to your git provider and test the connection. You should get a HTTP response code.