In this blog post, I will show you how to write End to End Tests in Kubernetes to verify the various objects in a Kubernetes cluster like Pods, Services, Nodes, Namespaces etc.
I would highly recommend you to read my previous blog about End to End Testing in Kubernetes for context setting prior to looking at the below set of tests –
End to End Testing in Kubernetes
If you want to interact with the Kubernetes API, there is no need to write your own library. You can leverage a number of available client libraries for this purpose. I am using the Python API Client for Kubernetes to interact with the cluster in Cloud.
Official Python client library for Kubernetes –
https://github.com/kubernetes-client/python
Documentation for Kubernetes API Endpoints –
https://github.com/kubernetes-client/python/tree/master/kubernetes#documentation-for-api-endpoints
The below tests will verify the pod count and service count in the ‘default’ namespace —
The below test will iterate through all the namespaces in the K8s cluster and list it down –
The below set of tests will iterate through all the endpoints, services, nodes and pods in the K8s cluster and list them down —
The below tests lists pods and services for a specific namespace —
Using the Python API Client we saw how to interact with the K8s components in the cluster hosted in AWS or Azure. By running a set of End to End Tests we can easily determine the health of the cluster. We have just scratched the surface with these E2E Tests — you can improvise on top of these tests to interact with any K8s object in the cluster and verify functionalities.
Categories: Kubernetes
Leave a Reply