Skip to content

Incorrect label in kubectl get pods command in Chapter 7: Service DiscoveryΒ #57

@usmans58

Description

@usmans58

πŸ› Issue: Incorrect label in kubectl get pods command in Chapter 7 (Service Discovery)

πŸ“˜ Context

In Chapter 7: Service Discovery of Terraform: Up & Running, the book provides this command to retrieve the name of the alpaca pod:

$ ALPACA_POD=$(kubectl get pods -l app=alpaca -o jsonpath='{.items[0].metadata.name}')

❗ Problem

The above command fails with the following error:

error: error executing jsonpath "{.items[0].metadata.name}": Error executing template: array index out of bounds: index 0, length 0.

This occurs because no pods match the label app=alpaca.

πŸ” Root Cause

The deployment created earlier in the chapter labels the pods with:

labels:
  app: alpaca-prod

Therefore, the kubectl command is using the wrong label selector.

βœ… Suggested Fix

The corrected command should be:

ALPACA_POD=$(kubectl get pods -l app=alpaca-prod -o jsonpath='{.items[0].metadata.name}')

This properly matches the label used in the deployment and allows the command to succeed without an index out-of-bounds error.

πŸ™ Request

Please update the command in Chapter 7 and/or the example code repository so that readers don’t run into this issue.

Thanks for maintaining such a helpful and practical book!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions