Read Kubectl last applied config with Python
When working with Kubernetes you most likely will work with kubectl, either in a direct or an indirect fashion. kubectl, allows you to run commands against Kubernetes clusters. You can use kubectl to deploy applications, inspect and manage cluster resources, and view logs.
Last applied config
An interesting datapoint in many cases is, what is the last configuration that has been pushed to the cluster, using kubectl. As you might have many people / scripts interacting with your kubernetes cluster it is highly valuable to be able to find out what the last config was that was pushed into the cluster.
When in need for this information you can leverage the Kubernetes APIs to get the information. The below is a “cleaned” version of an API request to show information on a service. The shown part is a sub part of the full response and falls under “metadata”.”annotations”.”kubectl.kubernetes.io/last-applied-configuration” .
{
"apiVersion": "v1",
"kind": "Service",
"metadata": {
"annotations": {},
"labels": {
"k8s-app": "kubernetes-dashboard"
},
"name": "kubernetes-dashboard",
"namespace": "kubernetes-dashboard"
},
"spec": {
"ports": [{
"port": 443,
"targetPort": 8443
}],
"selector": {
"k8s-app": "kubernetes-dashboard"
}
}
}