{"id":13616086,"url":"https://github.com/alexellis/run-job","last_synced_at":"2025-04-09T20:13:10.439Z","repository":{"id":58668880,"uuid":"532929225","full_name":"alexellis/run-job","owner":"alexellis","description":"Run a Kubernetes Job and get the logs when it's done 🏃‍♂️","archived":false,"fork":false,"pushed_at":"2024-08-13T22:32:56.000Z","size":11883,"stargazers_count":211,"open_issues_count":8,"forks_count":7,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-09T20:12:59.696Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://blog.alexellis.io/fixing-the-ux-for-one-time-tasks-on-kubernetes/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alexellis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["alexellis"]}},"created_at":"2022-09-05T14:10:29.000Z","updated_at":"2025-03-23T10:52:31.000Z","dependencies_parsed_at":"2024-02-01T10:48:39.658Z","dependency_job_id":"59cfbd0d-e41e-4424-80b3-3454abd6e315","html_url":"https://github.com/alexellis/run-job","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexellis%2Frun-job","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexellis%2Frun-job/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexellis%2Frun-job/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexellis%2Frun-job/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexellis","download_url":"https://codeload.github.com/alexellis/run-job/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248103872,"owners_count":21048245,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T20:01:23.399Z","updated_at":"2025-04-09T20:13:10.411Z","avatar_url":"https://github.com/alexellis.png","language":"Go","funding_links":["https://github.com/sponsors/alexellis","https://img.shields.io/static/v1?label=Sponsor\u0026message=%E2%9D%A4\u0026logo=GitHub\u0026link=https://github.com/sponsors/alexellis"],"categories":["Go"],"sub_categories":[],"readme":"## run-job 🏃‍♂️\n\n[![Sponsor this](https://img.shields.io/static/v1?label=Sponsor\u0026message=%E2%9D%A4\u0026logo=GitHub\u0026link=https://github.com/sponsors/alexellis)](https://github.com/sponsors/alexellis)\n[![Github All Releases](https://img.shields.io/github/downloads/alexellis/run-job/total.svg)]()\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![build](https://github.com/alexellis/run-job/actions/workflows/build.yml/badge.svg)](https://github.com/alexellis/run-job/actions/workflows/build.yml)\n\nThe easiest way to run a simple one-shot job on Kubernetes.\n\nrun-job 🏃‍♂️ does the following with a simple YAML file definition:\n* Creates a Kubernetes Job\n* Watches until it passes or fails\n* Collects its logs (if available)\n* Deletes the job\n\nIt's primary usecase is for [checking OpenFaaS installations for customers](https://github.com/openfaas/config-checker) where it requires a service account to access various resources in a controlled way.\n\n## Examples\n\nThe first example is a real-world job for OpenFaaS customers, you probably won't run this example yourself, but read over it to learn the syntax and options. Then feel free to try Example 2 and 3, which anyone should be able to run.\n\nThe `image:` field in the Job YAML is for a container image that can be pulled by the cluster.\n\n\u003e Note: the examples in this repo are built with the `faas-cli publish` command because it can create multi-arch container images that work on PCs and ARM devices. You can build your images however you like, or by manually typing in various buildx commands for multi-arch.\n\n### Example 1 - a customer diagnostics tool with a service account\n\nCreate a `job.yaml` file:\n\n```yaml\nname: checker\nimage: ghcr.io/openfaas/config-checker:latest\nnamespace: openfaas\nsa: openfaas-checker\n```\n\nDownload run-job from [the releases page](https://github.com/alexellis/run-job/releases), or use arkade:\n\n```bash\n$ arkade get run-job\n```\n\nThen start the job defined in `job.yaml` and export the logs to a `report.txt` file:\n\n```bash\n$ run-job \\\n    -f job.yaml \\\n    -out report.txt\n```\n\n### Example 2 - kubectl with RBAC\n\nIn order to access the K8s API, [an RBAC file](/examples/kubectl/rbac.yaml) is required along with a `serviceAccount` field in the job YAML.\n\nThe command `kubectl get nodes -o wide` configured [in the job's YAML file](/examples/kubectl/kubectl_get_nodes_job.yaml).\n\n```bash\n$ kubectl apply -f ./examples/kubectl/rbac.yaml\n$ run-job -f ./examples/kubectl/kubectl_get_nodes_job.yaml\n\nCreated job get-nodes.default (e99686bf-2064-4659-8160-ec28b5d820f0)\n...\nJob get-nodes.default (e99686bf-2064-4659-8160-ec28b5d820f0) succeeded \nDeleted job get-nodes\n\nRecorded: 2023-10-20 12:44:37.097486774 +0000 UTC\n\nNAME           STATUS   ROLES                       AGE   VERSION        INTERNAL-IP   EXTERNAL-IP      OS-IMAGE             KERNEL-VERSION\nk3s-agent-1    Ready    \u003cnone\u003e                      63d   v1.27.4+k3s1   192.168.3.4   101.58.106.152   Ubuntu 22.04.2 LTS   5.15.0-73-generic\nk3s-server-1   Ready    control-plane,etcd,master   71d   v1.27.4+k3s1   192.168.3.1   101.58.106.241   Ubuntu 22.04.2 LTS   5.15.0-73-generic\nk3s-server-2   Ready    control-plane,etcd,master   62d   v1.27.4+k3s1   192.168.3.2   101.58.106.122   Ubuntu 22.04.2 LTS   5.15.0-73-generic\nk3s-server-3   Ready    control-plane,etcd,master   62d   v1.27.4+k3s1   192.168.3.3   101.58.106.98    Ubuntu 22.04.2 LTS   5.15.0-73-generic\n```\n\n### Example 3 - light relief with ASCII cows\n\nSee also: [examples/cows/Dockerfile](/examples/cows/Dockerfile)\n\ncows.yaml:\n\n```yaml\n$ cat \u003c\u003cEOF \u003e cows.yaml\n# Multi-arch image for arm64, amd64 and armv7l\nimage: alexellis2/cows:2022-09-05-1955\nname: cows\nEOF\n```\n\nRun the job:\n\n```bash\n$ run-job -f cows.yaml\n\n        ()  ()\n         ()()\n         (oo)\n  /-------UU\n / |     ||\n*  ||w---||\n   ^^    ^^\nEh, What's up Doc?\n```\n\nOr run from the examples repo:\n\n```bash\nrun-job -f ./examples/cows/cows_job.yaml\n```\n\n## Why does this tool exist?\n\nRunning a Job in Kubernetes is confusing:\n\n* The spec is very different to what we're used to building (Pods/Deployments)\n* The API is harder to use to check if things worked since it uses conditions\n* Getting the name of the Pod created by a job is a pain\n* Getting the logs from a job is a pain, and needs multiple get/describe/logs commands\n\nInspired by:\n\n* [alexellis/jaas](https://github.com/alexellis/jaas) built in 2017, now deprecated for running jobs on Docker Swarm\n* [stefanprodan/kjob](https://github.com/stefanprodan/kjob) by Stefan Prodan, now unmaintained for 3 years\n\n## Can I get a new option / field / feature?\n\nRaise an issue and explain why you need it and whether it's for work or pleasure.\n\nPRs will not be approved prior to an issue being created and agreed upon.\n\nLicense: MIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexellis%2Frun-job","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexellis%2Frun-job","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexellis%2Frun-job/lists"}