Sample .NET cron job application for Kubernetes
In the steps below, and in the kube.yml files in this solution, replace my-registry-host
with the name of your container registry/docker repository
- cd into the solution root
- Build the docker image
docker build . -f ./MyCronJob/Dockerfile -t my-registry-host/mycronjob:latest
- Push the docker image to your repository
docker push my-registry-host/mycronjob:latest
- Install
kubectl
if you haven't already, then ensure you are connected to the kubernetes cluster
# Use the context to select the kubernetes cluster
# Replace context-name with the name of your kubernetes context
kubectl config use-context context-name
# Check that you can view the pods
kubectl get pods
- Create the cron job in Kubernetes
Job 1:
kubectl create -f ./MyCronJob/Job1/kube.yml
Job 2:
kubectl create -f ./MyCronJob/Job2/kube.yml
- When a job runs, a pod will be created. This will run the relevant background service to completion/failure and then stop the application.