helm icon indicating copy to clipboard operation
helm copied to clipboard

Example with Port Forwarding

Open stephenwilliams opened this issue 7 years ago • 4 comments
trafficstars

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?

stephenwilliams avatar Jun 09 '18 17:06 stephenwilliams

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.

qmfrederik avatar Jun 13 '18 07:06 qmfrederik

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);
                }
            }
        }

stephenwilliams avatar Jun 15 '18 00:06 stephenwilliams

@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.

jpoon avatar Jul 20 '18 05:07 jpoon

@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.

stephenwilliams avatar Jul 23 '18 14:07 stephenwilliams