Skip to content
This repository has been archived by the owner on Jun 24, 2020. It is now read-only.

Example with Port Forwarding #9

Open
stephenwilliams opened this issue Jun 9, 2018 · 4 comments
Open

Example with Port Forwarding #9

stephenwilliams opened this issue Jun 9, 2018 · 4 comments

Comments

@stephenwilliams
Copy link

I've attempted to figure out how to get this working with Port Forwarding from the Kubernetes-Client/csharp library but I've yet to have any success. Would you be able to provide an example for connecting over that method?

@qmfrederik
Copy link
Owner

You should be able to get this to work if you're a bit adventurous.

Can you give this a try:

  1. Make sure you use the latest version of KubernetsClient (1.0.0 or 1.1.0-gf488d54ce7)
  2. Use the code in the TillerLocator to find the Tiller pod, though you'll need to get the namespace and name of the Tiller pod
  3. Use KubernetesClient.WebSocketNamespacedPodPortForwardAsync to connect to the Tiller port on the Tiller pod over port forwarding. This will return a Stream
  4. That stream is muxed and you'll need to use the StreamDemuxer to demux it into a stream which you can pass to the constructor of the TillerClient class.

@stephenwilliams
Copy link
Author

I've tried the following with no success:

        private static void Main(string[] args) => MainAsync().GetAwaiter().GetResult();

        private static async Task MainAsync()
        {

            var kubeConfig = KubernetesClientConfiguration.BuildConfigFromConfigFile();
            kubeConfig.SkipTlsVerify = true;
            var kubernetes = new Kubernetes(kubeConfig);

            var selector = "app=helm,name=tiller";

            var pod = (await kubernetes.ListNamespacedPodAsync("kube-system", labelSelector: selector))?.Items.FirstOrDefault();

            if (pod == null)
            {
                return;
            }


            using (var webSocket = await kubernetes.WebSocketNamespacedPodPortForwardAsync(
                name: pod.Metadata.Name,
                @namespace: "kube-system",
                ports: new[] {44134}
            ))
            using (var muxer = new StreamDemuxer(webSocket))
            {
                muxer.Start();

                using (var stream = muxer.GetStream(0, 1))
                {
                    TillerClient client = new TillerClient(() => stream);
                    var version = await client.GetVersion();

                    Console.WriteLine(version.SemVer);
                }
            }
        }

@jpoon
Copy link

jpoon commented Jul 20, 2018

@stephenwilliams did you end up figuring this out? I'm in the same boat. My workaround right now is shelling out to kubectl port-forward which is suboptimal.

@stephenwilliams
Copy link
Author

@jpoon I did not, I ended up doing the same in my testing but I've also moved away from using Helm due to a few bugs that concerned me.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants