I know that I can perform this command to see all the pods that have a certain label : kubectl get pods -l importance=normal
Is there a command that would allow me to get the deployments that create the pods with the label importance=normal
?
I want to find all deployments what have the label importance=normal
found in the spec/template/metadata/labels (see my deployment yaml below).
I found this link(https://kubernetes.io/docs/tasks/access-application-cluster/list-all-running-container-images/#list-container-images-filtering-by-pod-label) and started to create the following command but I could not get it to work -
kubectl get deployments -namespace prod -o jsonpath='{range .items[*]}{"\n"}{.spec.template.metadata.labels}{":\t"}{", "}{end}{end}' |\ sort```
My deployment yaml looks like the following:
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
app.kubernetes.io/managed-by: Helm
deployment.kubernetes.io/revision: "11"
meta.helm.sh/release-name: service-qa
meta.helm.sh/release-namespace: prod
source: https://gitlab.services.com/service
creationTimestamp: "2019-04-07T12:51:03Z"
generation: 22
labels:
app.kubernetes.io/managed-by: Helm
chart: service-0.1.0
name: service-deployment
namespace: qa
resourceVersion: "577488289"
uid: cd2fdeb4-5933-11e9-ad6d-02211a607320
spec:
progressDeadlineSeconds: 600
replicas: 2
revisionHistoryLimit: 3
selector:
matchLabels:
app: service-selector
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
type: RollingUpdate
template:
metadata:
annotations:
kubectl.kubernetes.io/restartedAt: "2022-11-13T08:19:36-06:00"
creationTimestamp: null
labels:
app: service-selector
importance: normal
version: current