Skip to content

Switch to version 1.0.0 : node-fetch behind proxy #2161

Closed as not planned
Closed as not planned

Description

@Leer0r

Describe the bug
I'm currently using the 1.0.0 version, and I notice on the changelog that the project switched from request to node-fetch for APIs call. With request I can use HTTP_PROXY and HTTPS_PROXY variables to access to my cluster, but the new package doesn't allowed to do such things. In my research, I've seen a hint of @lselden who is using the global-agent package to import the proxy setting. I use it and my client can now reach the kubernetes API, but I have the Unauthorized error, so I suppose that some kubeconfig authorization are not in the forwarded request.
image

Client Version
1.0.0

Server Version
1.31.3

To Reproduce

  1. Install @kubernetes/client-node stable version on a nodeJS project behind a proxy
  2. Install global-agent package and bootstrap it
  3. Create a kubernetes API with makeApiClient
  4. Try to use any fetch method from the client API

Expected behavior
The API return the expected information by reaching the cluster

Example Code
Simple code

import {bootstrap} from 'global-agent'
import k8s, {CoreV1Api, Metrics, V1NodeCondition} from '@kubernetes/client-node'

//PROXY settings
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
process.env["GLOBAL_AGENT_HTTP_PROXY"] = process.env.HTTP_PROXY || "http://my.proxy.address:my.proxy.port";
bootstrap({
  forceGlobalAgent: true
})

const config = new k8s.KubeConfig()
config.loadFromDefault()
const kube_api = config.makeApiClient(k8s.CoreV1Api)

kube_api.listNode()

Environment (please complete the following information):

  • OS: Ubuntu (WSL) and Ubuntu (bare metal)
  • Node.js version v23.3.0
  • Cloud runtime On-prem K3S install

Additional context
When I use the same kubeconfig file with kubectl, I can access to the cluster
image
Here I'm on my local WSL, accessing the remote cluster

Activity

  1. mstruebing commented on Jan 14, 2025

    @mstruebing
    Member

    Does it work if you set the proxy configuration in your KUBECONFIG?

    Reference:

  2. Leer0r commented on Jan 16, 2025

    @Leer0r
    Author

    Adding the proxy-url field in the kubeconfig file seems not handle by the client, I have the same issue than before. Regarding the small hack from @geisbruch, it not work due to a missing property:
    Image
    Here is the plain code if you need it

    type ApiConstructor<T extends ApiType> = new (config: Configuration) => T;
    function connectToKubeClusterWithProxy(proxyURL: string) {
        const kc = new k8s.KubeConfig();
        const originalMakeApiClient = kc.makeApiClient;
        kc.makeApiClient = function <T extends ApiType>(api: ApiConstructor<T>): T {
            const client = originalMakeApiClient.call(kc, api);
            client.interceptors.push(async (config: Configuration) => {
                config.proxy=proxyURL;
            });
            return client as T;
        };
    }

    Also the ApiConstructor interface is not exported by default, so I need to recreate it in my code

  3. k8s-triage-robot commented on Apr 16, 2025

    @k8s-triage-robot

    The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

    This bot triages un-triaged issues according to the following rules:

    • After 90d of inactivity, lifecycle/stale is applied
    • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
    • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

    You can:

    • Mark this issue as fresh with /remove-lifecycle stale
    • Close this issue with /close
    • Offer to help out with Issue Triage

    Please send feedback to sig-contributor-experience at kubernetes/community.

    /lifecycle stale

  4. added
    lifecycle/stale
    on Apr 16, 2025
  5. k8s-triage-robot commented on May 16, 2025

    @k8s-triage-robot

    The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.

    This bot triages un-triaged issues according to the following rules:

    • After 90d of inactivity, lifecycle/stale is applied
    • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
    • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

    You can:

    • Mark this issue as fresh with /remove-lifecycle rotten
    • Close this issue with /close
    • Offer to help out with Issue Triage

    Please send feedback to sig-contributor-experience at kubernetes/community.

    /lifecycle rotten

  6. added
    lifecycle/rotten
    and removed
    lifecycle/stale
    on May 16, 2025
  7. k8s-triage-robot commented on Jun 15, 2025

    @k8s-triage-robot

    The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

    This bot triages issues according to the following rules:

    • After 90d of inactivity, lifecycle/stale is applied
    • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
    • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

    You can:

    • Reopen this issue with /reopen
    • Mark this issue as fresh with /remove-lifecycle rotten
    • Offer to help out with Issue Triage

    Please send feedback to sig-contributor-experience at kubernetes/community.

    /close not-planned

  8. k8s-ci-robot commented on Jun 15, 2025

    @k8s-ci-robot
    Contributor

    @k8s-triage-robot: Closing this issue, marking it as "Not Planned".

    Details

    In response to this:

    The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

    This bot triages issues according to the following rules:

    • After 90d of inactivity, lifecycle/stale is applied
    • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
    • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

    You can:

    • Reopen this issue with /reopen
    • Mark this issue as fresh with /remove-lifecycle rotten
    • Offer to help out with Issue Triage

    Please send feedback to sig-contributor-experience at kubernetes/community.

    /close not-planned

    Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    lifecycle/rotten

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions