Simplifying Kubernetes Health Checks with BusyBox on Minikube

In the realm of microservices and cloud-native applications, efficiency and minimalism are crucial. This is where BusyBox shines, bringing together the most commonly used UNIX utilities into a single lightweight executable. Ideal for environments where resources are scarce or need to be optimized, such as Docker containers or embedded systems, BusyBox ensures that developers and administrators have access to essential tools without the overhead of a full OS.

Deploying BusyBox in Minikube

To deploy BusyBox, we can simply create a YAML file named busybox.yaml with the following configurations:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: busybox
  namespace: default
  labels:
    app: busybox
spec:
  replicas: 1
  selector:
    matchLabels:
      app: busybox
  template:
    metadata:
      labels:
        app: busybox
    spec:
      containers:
      - name: busybox-container
        image: busybox:latest
        # Keep the container running
        command: [ "/bin/sh", "-c", "--" ]
        args: [ "while true; do sleep 30; done;" ]
        resources:
          requests:
            cpu: 30m
            memory: 64Mi
          limits:
            cpu: 100m
            memory: 128Mi

Then we can run the following command to apply the .yaml configurations:

kubectl apply -f busybox.yaml

Creating a Simple Health Check

Access the BusyBox shell and create the index.html file, as follows:

kubectl exec -it busybox -- bin/sh
echo "Application is healthy" > /www/index.html

Using BusyBox for Health Checks

Provided that there is an existing application running in the minikube cluster and we run the following command holding its application IP – note that the namespace of reference is called development:

kubectl get pods -n development -o wide

Let’s say that we have the quote service running as per the following:

quote-deployment-7494cbf559-h8rcd 1/1 Running 0 8m2s 10.244.0.9 minikube

Now, we can connect with the application:

wget 10.244.0.9:8080

and inspect the content of the index.html:

Connecting to 10.244.0.9:8080 (10.244.0.9:8080)
saving to 'index.html'
index.html           100% |********************************************************************|   138  0:00:00 ETA
'index.html' saved
/ # cat index.html 
{
    "server": "itchy-blueberry-ph0yl0ly",
    "quote": "668: The Neighbor of the Beast.",
    "time": "2024-03-25T16:06:54.802383732Z"
}/ # 

Posted on March 25, 2024, in Development and Testing and tagged . Bookmark the permalink. Leave a comment.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.