I am trying to retrieve the kubernetes last-applied-configuration from a service yaml (under metadata annoations) using kubectl -o jsonpath, but the name of the field is "kubectl.kubernetes.io/last-applied-configuration". I believe the parser is getting confused due to the dots in the actual name field, since it uses dots for child object designation.
e.g. (Running on Windows)
kubectl -lapp=myapp get service -o jsonpath="{range .items[*]}{
.metadata.annotations}{\"\n\"}{end}"
shows the map of resulting values as expected
map[kubectl.kubernetes.io/last-applied-configuration:{"kind":"Service","apiVersion":"v1","metadata":{"name":"myapp","namespace":"mynamespace",
"creationTimestamp":null,"labels":{"app":"myapp","version":"1.0"}},"spec":{"ports":[{"name":"http","protocol":"TCP","port":80,"ta
rgetPort":8080}],"selector":{"app":"myapp","version":"1.0"},"type":"NodePort"},"status":{"loadBalancer":{}}}]
In this case, the kubectl.kubernetes.io/last-applied-configuration is the only thing in the annotations, but that is not always the case.
The problem comes about when I try to drill down to just the last-applied-configuration.
e.g.
kubectl -lapp=myapp get service -o jsonpath="{range .items[*]}{
.metadata.annotations.kubectl.kubernetes.io/last-applied-configuration}{\"\n\"}{end}"
Returns no information.
I have also tried
kubectl -lapp=myapp get service -o jsonpath="{range .items[*]}{
.metadata.annotations['kubectl.kubernetes.io/last-applied-configuration']}{\"\n\"}{end}"
and
kubectl -lapp=myapp get service -o jsonpath="{range .items[*]}{['metadata']['annotations']['kubectl.kubernetes.io/last-applied-configuration']}{\"\n\"}{end}"
to no avail.
I'm expecting the results to be simply the value of the kubectl.kubernetes.io/last-applied-configuration
The kubectl apply command writes the contents of the configuration file to the kubectl.kubernetes.io/last-applied-configuration annotation. This is used to identify fields that have been removed from the configuration file and need to be cleared from the live configuration.
To see the Deployment rollout status, run kubectl rollout status deployment/nginx-deployment . Notice that the Deployment has created all three replicas, and all replicas are up-to-date (they contain the latest Pod template) and available.
Where does the kubectl command store its configuration file? [] The configuration information is stored in the $HOME/. kube/config file. [] The configuration information is stored in environment variables in the current shell.
kubectl apply view-last-applied service -lapp=myapp -o json
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With