liveBook · Manning

Label selector

As explained in gRPC Microservices in Go

A Kubernetes selector is a field or matching expression that identifies resources, such as Pods, according to their labels or other selection criteria.

A Kubernetes label selector lets a Service find Pods by labels and route traffic to matching endpoints. In a production-style deployment, a Service can expose payment or order Pods while keeping client access separate from Pod placement. section 8.2.6

Use selectors to control which Pods receive Service traffic:

  • Match a Service selector such as app: payment to Pods carrying the corresponding label. section 8.2.6
  • Route requests through a LoadBalancer or NodePort while Kubernetes forwards them to a matching Pod. section 8.2.6
  • Share one selector across stable and canary Deployments so requests can reach both versions during gradual rollout. section 8.4.3

Payment Service selector

A Service named payment selects Pods labeled app: payment, exposes port 80, forwards TCP traffic to targetPort 8081, and uses a LoadBalancer for public access. section 8.2.6

apiVersion: v1
kind: Service
metadata:
  name: payment
  labels:
    app: payment
spec:
  selector:
    app: payment          #1
  ports:
    - name: grpc          #2
      port: 80            #3
      protocol: TCP       #4
      targetPort: 8081    #5
  type: LoadBalancer      #6

Inspect the complete Service manifest showing metadata, selector, gRPC port naming, TCP protocol, target port, and LoadBalancer exposure. section 8.2.6

Figure 8.11 Canary deployment

Trace how a shared selector enables requests to move progressively from v1 Pods to v2 Pods during a canary deployment. section 8.4.3

How gRPC Microservices in Go covers it

How deep it goes
Defines Service–Pod matching and shared selectors for canary rollout, without detailing selector-expression syntax.
Examples
Uses payment and order Services plus v1 and v2 canary Deployments sharing a selector.
What you can do after
Apply it via Kubernetes YAML to route Service requests to labeled Pods and support staged rollout.
How it connects
Connects Kubernetes Services, Pods, labels, load balancing, Deployments, and canary deployment.

Also explained in

Compare how 7 books explain label selector →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of gRPC Microservices in Go. The section links point to the parts of the book it draws on.