Answers: <ol>
  <li><blockquote>
    <p>kubectl port-forward forwards connections to a local port to a port on
    a pod. Compared to kubectl proxy, kubectl port-forward is more generic
    as it can forward TCP traffic while kubectl proxy can only forward
    HTTP traffic. Generally speaking, using port forwarding you could get
    on your ‘localhost’ any services launched in your cluster.</p>
  </blockquote>
  
  <p><a href="https://stackoverflow.com/questions/58360323/difference-between-kubectl-port-forwarding-and-proxy">https://stackoverflow.com/questions/58360323/difference-between-kubectl-port-forwarding-and-proxy</a></p></li>
  <li><p>It does not make a lot of sence to run 'kubectl proxy' from inside VM running k8s cluster. Kubectl is your client tool, so stick with it outside of cluster range.</p></li>
  <li><p>The way you would access production services, for the most part if your service is DB oriented stick with ClusterIP. If you want to externally access some Web/HTTP service expose it as a Load Balancer or an Ingress ( in case u have N of them ). If you want to test the DB you could just run a dummy pod and execute some sql-client commands from there.</p></li>
  </ol>
  
Answers: CC BY-SA 4.0
Answers: 2020-03-09T09:21:35.870Z
Answers: I guess that running proxy/port-forward in the box will enable access to the cluster on the guest machine, which should be visible in the host.This is why I am asking where to run the command. My current VM setting seems to propagate all ports to host. I'm using one-node cluster to run some apps, but I need to connect to the DB pod with some UI tool(it is more efficient for me). I will check possibilities how to run Ingress/LoadBalancer in my cluster.
Answers: Zveratko
Answers: CC BY-SA 4.0
Answers: 2020-03-09T09:31:22.227Z
Answers: For me the cleanest way is to explicitly use kubectl and set up kubeconfig, all those hacks are temporary solutions that soon or later might fail. Also you might benefit for authentication over multiple clusters if needed.
Answers: Recoba20
Answers: CC BY-SA 4.0
Answers: 2020-03-09T10:25:35.077Z
Answers: I have of course "host" kubectl. I was just suprised that I can actually use it in the guest and has been wondering what it does exactly. So to wrap up - I will run a pod with DB, run kubectl proxy from host and done. I have had some issues and I suspected PostgreSQL to be limited to localhost, but fortunatelly I have been proven otherwise in the Helm chart page.
Answers: Zveratko
Answers: CC BY-SA 4.0
Answers: 2020-03-06T17:11:43.463Z
Answers: 2020-03-07T07:16:18.413Z
Answers: 2020-03-07T07:16:18.413Z
Answers: Recoba20
Answers: <p>To access Kubernetes you typically use <code>port-forward</code>, like this (take from KubeApps)</p>
  <pre class="lang-sh prettyprint-override"><code>$ kubectl port-forward -n kubeapps svc/kubeapps 8080:80
  Forwarding from 127.0.0.1:8080 -&gt; 8080
  Forwarding from [::1]:8080 -&gt; 8080
  </code></pre>
  <p>If you want to make it public so your port-forward listens to all ip addresses, you can use <code>--address 0.0.0.0</code> as documented in <code>kubectl port-forward --help</code>,</p>
  <pre class="lang-sh prettyprint-override"><code>$ kubectl port-forward -n kubeapps svc/kubeapps 8080:80 --address 0.0.0.0
  Forwarding from 0.0.0.0:8080 -&gt; 8080
  </code></pre>
  <p>Now your host is redirecting traffic from 8080 to inside the Kubernetes cluster.</p>
  
Answers: CC BY-SA 4.0
Answers: 2022-06-08T18:26:59.640Z
Answers: 2022-06-08T18:26:59.640Z
Answers: Evan Carroll
Body: <p>I am running k8s cluster for evaluation purposes inside some vagrant box. I have external kubectl access. I was able to get PostgreSQL helm template running on the cluster. But now let say I want to access it outside of the k8s(or VM actually).</p>
  
  <p>There is a problem that I am not very educated in the niceties of Host to Quest communication in VM not to speak about the k8s stack. By empirical research I have found that turning service to NodePort makes it available outside the k8s. But as I said the installed PostgreSQL service is ClusterIP so I want to access it outside aswell without finding a way to turn it to NodePort. So there is couple of noob questions here</p>
  
  <ol>
  <li>what is difference between <code>kubectl proxy</code> and <code>kubectl port-forward</code>?</li>
  <li>what is different when executing <code>kubectl proxy</code> from inside VM running k8s cluster and running the same kubectl command on the host?</li>
  <li>what is the usual way to make services available outside of the cluster, when using the cluster just for development?  </li>
  <li>is this quote true? 
  
  <blockquote>
    <p>port forwarding is not needed when using private network and accessing guest from host with guest private ip, port forwarding is used to access guest with localhost/127.0.0.1 the ports are then forwarded</p>
  </blockquote></li>
  </ol>
  
Tags: <kubernetes><kubectl><vm>
Title: Accessing k8s outside of VM
UserDisplayName: Zveratko
ThreadText: # Accessing k8s outside of VM
  
  (Asked by: username_0 on 2020-03-06)
  
  I am running k8s cluster for evaluation purposes inside some vagrant box. I have external kubectl access. I was able to get PostgreSQL helm template running on the cluster. But now let say I want to access it outside of the k8s(or VM actually).
  
  There is a problem that I am not very educated in the niceties of Host to Quest communication in VM not to speak about the k8s stack. By empirical research I have found that turning service to NodePort makes it available outside the k8s. But as I said the installed PostgreSQL service is ClusterIP so I want to access it outside aswell without finding a way to turn it to NodePort. So there is couple of noob questions here
  
  1. what is difference between `kubectl proxy` and `kubectl port-forward`?
  2. what is different when executing `kubectl proxy` from inside VM running k8s cluster and running the same kubectl command on the host?
  3. what is the usual way to make services available outside of the cluster, when using the cluster just for development?
  4. is this quote true?
     > port forwarding is not needed when using private network and accessing guest from host with guest private ip, port forwarding is used to access guest with localhost/127.0.0.1 the ports are then forwarded
  
  **Tags:** kubernetes, kubectl, vm
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2020-03-06. Score: 2
  
  1. > kubectl port-forward forwards connections to a local port to a port on
     > a pod. Compared to kubectl proxy, kubectl port-forward is more generic
     > as it can forward TCP traffic while kubectl proxy can only forward
     > HTTP traffic. Generally speaking, using port forwarding you could get
     > on your ‘localhost’ any services launched in your cluster.
  
     <https://stackoverflow.com/questions/58360323/difference-between-kubectl-port-forwarding-and-proxy>
  2. It does not make a lot of sence to run 'kubectl proxy' from inside VM running k8s cluster. Kubectl is your client tool, so stick with it outside of cluster range.
  3. The way you would access production services, for the most part if your service is DB oriented stick with ClusterIP. If you want to externally access some Web/HTTP service expose it as a Load Balancer or an Ingress ( in case u have N of them ). If you want to test the DB you could just run a dummy pod and execute some sql-client commands from there.
  
  > **Comments:**
  > **username_0**: I guess that running proxy/port-forward in the box will enable access to the cluster on the guest machine, which should be visible in the host.This is why I am asking where to run the command. My current VM setting seems to propagate all ports to host. I'm using one-node cluster to run some apps, but I need to connect to the DB pod with some UI tool(it is more efficient for me). I will check possibilities how to run Ingress/LoadBalancer in my cluster.  
  > **username_1**: For me the cleanest way is to explicitly use kubectl and set up kubeconfig, all those hacks are temporary solutions that soon or later might fail. Also you might benefit for authentication over multiple clusters if needed.  
  > **username_0**: I have of course "host" kubectl. I was just suprised that I can actually use it in the guest and has been wondering what it does exactly. So to wrap up - I will run a pod with DB, run kubectl proxy from host and done. I have had some issues and I suspected PostgreSQL to be limited to localhost, but fortunatelly I have been proven otherwise in the Helm chart page.  
  
  ---
  
  ### Answer by username_2 on 2022-06-08. Score: 0
  
  To access Kubernetes you typically use `port-forward`, like this (take from KubeApps)
  
  ```sh
  $ kubectl port-forward -n kubeapps svc/kubeapps 8080:80
  Forwarding from 127.0.0.1:8080 -> 8080
  Forwarding from [::1]:8080 -> 8080
  
  ```
  
  If you want to make it public so your port-forward listens to all ip addresses, you can use `--address 0.0.0.0` as documented in `kubectl port-forward --help`,
  
  ```sh
  $ kubectl port-forward -n kubeapps svc/kubeapps 8080:80 --address 0.0.0.0
  Forwarding from 0.0.0.0:8080 -> 8080
  
  ```
  
  Now your host is redirecting traffic from 8080 to inside the Kubernetes cluster.
  
  
  ---
  
  