Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I retrieve just the kubectl.kubernetes.io/last-applied-configuration using kubectl -o jsonpath?

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

like image 432
user4611739 Avatar asked May 13 '19 18:05

user4611739


People also ask

What is 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.

How can I see the current configuration of a running deployment in Kubernetes?

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?

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.


1 Answers

kubectl apply view-last-applied service -lapp=myapp -o json
like image 183
Daniel Bruzual Avatar answered Sep 30 '22 08:09

Daniel Bruzual