How to have two have multiple fields for one selector in kubernetes

12/29/2020

At the moment I have the following config in one of my services:

spec:
  clusterIP: None
  ports:
  - name: grpc
    port: 9000
    protocol: TCP
    targetPort: 9000
  selector:
    app: my-first-app
    environment: production
    group: my-group
  type: ClusterIP

in the selector section, I need to add another app:

.
.
app: my-first-app my-second-app
.
.

How can I achieve this?

Thank you!

-- Moein
kubernetes

1 Answer

12/29/2020
selector:
  matchExpressions:
    - {key: app, operator: In, values: [my-first-app, my-second-app]}

Reference: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/

-- Abhijit Gaikwad
Source: StackOverflow