Skip to content

[Question] How to debug k8s:// gRPC resolver locally without in-cluster environment? #5382

@tangentgo

Description

@tangentgo

I am using the go-zero gRPC resolver with the k8s scheme for service discovery. My connection target is configured as k8s://namespace/service:port.

The Problem In the current implementation of resolver/internal/kubebuilder.go, the kubeBuilder.Build method relies on rest.InClusterConfig() to initialize the Kubernetes client。

When I attempt to run or debug my gRPC client locally (outside of a Kubernetes cluster), the application fails with the following error because the required service account tokens and environment variables

(KUBERNETES_SERVICE_HOST/KUBERNETES_SERVICE_PORT) are missing:
unable to load in-cluster configuration, KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT must be defined
Image

The problem can be solved by directly connecting through the service domain. However, switching between the two configuration files is a bit troublesome. I would like to know how to solve this problem when I am debugging locally.

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