Call endpoint from Kubernetes Cron Job
CronJob
s are a good choice. Here's a quick layout that runs 3 nginx pods accepting all traffic. Every minute, a Job
curls 1 of the 3 pods (always the same pod).
apiVersion: apps/v1beta1kind: Deploymentmetadata: name: main labels: app: nginxspec: replicas: 2 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.7.9 ports: - containerPort: 80---apiVersion: apps/v1beta1kind: Deploymentmetadata: name: singleton labels: app: nginx special: singletonspec: replicas: 1 selector: matchLabels: app: nginx special: singleton template: metadata: labels: app: nginx special: singleton spec: containers: - name: nginx image: nginx:1.7.9 ports: - containerPort: 80---kind: ServiceapiVersion: v1metadata: name: allpodsspec: selector: app: nginx ports: - protocol: TCP port: 80 targetPort: 80---kind: ServiceapiVersion: v1metadata: name: singletonspec: selector: special: singleton ports: - protocol: TCP port: 80 targetPort: 80---apiVersion: batch/v1beta1kind: CronJobmetadata: name: calloutspec: schedule: "*/1 * * * *" concurrencyPolicy: Forbid successfulJobsHistoryLimit: 1 failedJobsHistoryLimit: 1 jobTemplate: spec: template: spec: containers: - name: callout image: buildpack-deps:curl args: - /bin/sh - -ec - curl http://singleton restartPolicy: Never