kubernetes / client-go

Go client for Kubernetes.
Apache License 2.0
8.79k stars 2.91k forks source link

Failed to add a proxy into clientset. #1246

Closed ziyanjiang98 closed 3 months ago

ziyanjiang98 commented 1 year ago

Package name: k8s.io/client-go v0.15.11

Issue: Due to the network structure, I need to add a proxy-url so that the HTTP requests from the client-go can be sent out to my clusters's IP address.

However, I met errors when using the following code

// Collect local kubeconfig file.
kubeConfigPath := filepath.Join(homedir.HomeDir(), ".kube", "config")
config, configErr = clientcmd.BuildConfigFromFlags("", kubeConfigPath)
...

// Add a transport to the config.
parsedURL, _ := url.Parse("<my_socks_proxy_url>")
ProxyURL := http.ProxyURL(parsedURL)
Transport := &http.Transport{
    Proxy: ProxyURL,
}
config.Transport = Transport

// Initialize the client.
kubeClient, clientErr := kubernetes.NewForConfig(config)
....

Then I got the following error: Create kube client fails: using a custom transport with TLS certificate options or the insecure flag is not allowed

Wondering if there is a way that I can fix it?

liggitt commented 1 year ago

you probably want to set config.Proxy = http.ProxyURL(parsedURL) instead of constructing your own transport instance

ziyanjiang98 commented 1 year ago

Hi @liggitt , thanks for responding!

I do find the Proxy field in the latest package, but unfortunately there is no such field in k8s.io/client-go v0.15.11. Wondering if there is a workaround for the old version? Or if the proxy setting is only available for the latest version.

liggitt commented 1 year ago

it was added in v0.19.x

ziyanjiang98 commented 1 year ago

Sounds good! Will try to upgrade the package version in our repo. Thanks for the help!

k8s-triage-robot commented 5 months ago

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

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

You can:

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

/lifecycle stale

k8s-triage-robot commented 4 months ago

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:

You can:

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

/lifecycle rotten

k8s-triage-robot commented 3 months ago

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:

You can:

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

/close not-planned

k8s-ci-robot commented 3 months ago

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

In response to [this](https://github.com/kubernetes/client-go/issues/1246#issuecomment-2007549026): >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][1] > >Please send feedback to sig-contributor-experience at [kubernetes/community](https://github.com/kubernetes/community). > >/close not-planned > >[1]: https://www.kubernetes.dev/docs/guide/issue-triage/ Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.