Kubernetes Code Help
Budget: $10 – $30 USD
Design and implement a small program that finds pods in “bad” or “completed” states and forcibly delete them from the cluster, in order to avoid delaying deployments, or causing load on the Kubernetes API server.
• Write a program in any language that scans all pods in a Kubernetes cluster, and finds pods in specific states - “Terminating”, “Completed”, “Failed”
• If the pod has been in this state for more than N minutes (configurable and in argument to the program), delete the pod, either by force or normally.
• Write unit tests
The program should consider the cases where we want to forcefully delete, delete normally, or avoid taking action. Consider how this program will run on multiple clusters and how you would monitor the results across multiple clusters.
To test it, use the pod manifests, to reproduce a pod in Completed:
apiVersion: v1
kind: Pod
metadata:
name: successful-pod
namespace: default
spec:
containers:
- name: main
image: busybox:1.28
command: ["/bin/sh"]
args:
- "-c"
- "exit 0"
To test it, use the pod manifests, to reproduce a pod in Failed:
apiVersion: v1
kind: Pod
metadata:
name: failed-pod
namespace: default
spec:
containers:
- name: main
image: busybox:1.28
command: ["/bin/sh"]
args:
- "-c"
- "exit 1"
To test it, use the pod manifests, to reproduce a pod stuck in Terminating state:
apiVersion: v1
kind: Pod
metadata:
name: terminating-pod
namespace: default
spec:
terminationGracePeriodSeconds: 50000
containers:
- name: main
image: busybox:1.28
command: ["/bin/sh"]
args:
- "-c"
- "sleep 99999"
• Write a program in any language that scans all pods in a Kubernetes cluster, and finds pods in specific states - “Terminating”, “Completed”, “Failed”
• If the pod has been in this state for more than N minutes (configurable and in argument to the program), delete the pod, either by force or normally.
• Write unit tests
The program should consider the cases where we want to forcefully delete, delete normally, or avoid taking action. Consider how this program will run on multiple clusters and how you would monitor the results across multiple clusters.
To test it, use the pod manifests, to reproduce a pod in Completed:
apiVersion: v1
kind: Pod
metadata:
name: successful-pod
namespace: default
spec:
containers:
- name: main
image: busybox:1.28
command: ["/bin/sh"]
args:
- "-c"
- "exit 0"
To test it, use the pod manifests, to reproduce a pod in Failed:
apiVersion: v1
kind: Pod
metadata:
name: failed-pod
namespace: default
spec:
containers:
- name: main
image: busybox:1.28
command: ["/bin/sh"]
args:
- "-c"
- "exit 1"
To test it, use the pod manifests, to reproduce a pod stuck in Terminating state:
apiVersion: v1
kind: Pod
metadata:
name: terminating-pod
namespace: default
spec:
terminationGracePeriodSeconds: 50000
containers:
- name: main
image: busybox:1.28
command: ["/bin/sh"]
args:
- "-c"
- "sleep 99999"
Related categories:
Kubernetes