How to use the @kubernetes/client-node.PortForward function in @kubernetes/client-node

To help you get started, we’ve selected a few @kubernetes/client-node examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kubernetes-client / javascript / examples / typescript / port-forward / port-forward.ts View on Github external
import * as k8s from '@kubernetes/client-node';
import * as net from 'net';

const command = process.argv[2];

const kc = new k8s.KubeConfig();
kc.loadFromDefault();

const forward = new k8s.PortForward(kc);

// This simple server just forwards traffic from itself to a service running in kubernetes
// -> localhost:8080 -> port-forward-tunnel -> kubernetes-pod
// This is basically equivalent to 'kubectl port-forward ...' but in TypeScript.
const server = net.createServer((socket) => {
    forward.portForward('default', 'demo', [8080], socket, null, socket);
});

server.listen(8080, '127.0.0.1');
github pixel-point / kube-forwarder / src / renderer / store / modules / Connections.js View on Github external
function prepareK8sToolsWithCluster(cluster) {
  let kubeConfig

  try {
    kubeConfig = buildKubeConfig(cluster.config)
  } catch (error) {
    const message = typeof error.message === 'string'
      ? `\nError message:\n---\n${error.message.substr(0, 1000)}`
      : null
    throw buildSentryIgnoredError(`Cluster config is invalid.${message}`)
  }

  const k8sPortForward = new k8s.PortForward(kubeConfig)
  patchForward(k8sPortForward)

  return { k8sPortForward, kubeConfig }
}