Remote-access Guide

kubectl proxy remote access

by Vallie Schowalter Published 2 years ago Updated 2 years ago
image

Here is the overall strategy to setup remote access to your Kubernetes Dashboard:

  • Deploy SocketXP VPN agent Docker container in your K8 cluster.
  • Install the kubectl CLI utility locally on your laptop.
  • Setup the kubectl config file in your laptop with SocketXP Public URL, K8 SSL Certs, and Key.
  • Remote access your private Kubernetes cluster from your laptop using the kubectl CLI utility.
  • Run kubectl in proxy mode in your laptop.

More items...

Full Answer

What is the kubectl proxy?

The kubectl proxy: runs on a user's desktop or in a pod proxies from a localhost address to the Kubernetes apiserver client to proxy uses HTTP

How can I use kubectl CLI on a remote Kubernetes cluster?

The kubectl CLI utility talks to the Kubernetes cluster via the cluster’s API server. As long as we could make the cluster’s API server accessible from your laptop, we could access or manage your remote Kubernetes cluster or minikube through a local kubectl instance installed on your laptop.

How do I start a Kubernetes proxy server?

Using kubectl to start a proxy server. This command starts a proxy to the Kubernetes API server: kubectl proxy --port=8080 Exploring the Kubernetes API. When the proxy server is running, you can explore the API using curl, wget, or a browser. Get the API versions: curl http://localhost:8080/api/ The output should look similar to this:

Where can I find the kubectl config file?

Usually the kubectl config file is stored at: $Home/.kube/config in the master node of your remote Kubernetes cluster. This is the config file used by the kubectl utility installed in your remote cluster’s master node. Note: kubectl is one of the utilities installed in any Kubernetes cluster or minikube during a cluster setup.

image

How do I access Kubernetes dashboard remotely?

Ans: In a terminal window, enter kubectl proxy to make the Kubernetes Dashboard available. Open a browser and go to http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes–dashboard:/proxy/#!/login to display the Kubernetes Dashboard that was deployed when the cluster was created.

How do I access Kubernetes dashboard without proxy?

Enable additional Add-Onsmicrok8s enable ingress # Ingress exposes HTTP and HTTPS routes from outside the cluster to services within the cluster.microk8s enable dashboard # web-based Kubernetes user interface.microk8s enable dns # creates DNS records for services and pods.More items...•

How do I access Kubernetes pod from outside?

In Kubernetes, nodes, pods and services all have their own IPs....Ways to connectAccess services through public IPs. Use a service with type NodePort or LoadBalancer to make the service reachable outside the cluster. ... Access services, nodes, or pods using the Proxy Verb. ... Access from a node or pod in the cluster.

What does kubectl proxy do?

The proxy provides a secure connection between the cluster(API Server) and the client, this avoid you having to change all your applications to implement a security logic just to communicate to the cluster, this way, you authenticate once, and every application use this secure connection without any changes.

How do you expose Kubernetes service on the Internet?

From the Service type drop-down list, select Cluster IP. Click Expose. When your Service is ready, the Service details page opens, and you can see details about your Service. Under Cluster IP, make a note of the IP address that Kubernetes assigned to your Service.

How do I access Kubernetes service within cluster?

Access Applications in a Cluster1: Deploy and Access the Kubernetes Dashboard.2: Accessing Clusters.3: Configure Access to Multiple Clusters.4: Use Port Forwarding to Access Applications in a Cluster.5: Use a Service to Access an Application in a Cluster.6: Connect a Frontend to a Backend Using Services.More items...

How do I access ingress from outside?

If you want to allow external access you can also expose the nginx ingress controller as a LoadBalancer service. You can also use NodePort but you will have to manually point a load balancer to the port on your Kubernetes nodes.

How do I access my IP pod?

Finding a Pod's IP address from inside the PodFirst, we need to define an environment variable inside the Pod. ... Now run your Pod, or restart your Pod if it's already running.Start a shell inside a Pod with kubectl exec : ... Type env and you'll see that the Pod's IP address is now stored in an environment variable.More items...•

How do I get the URL for Kubernetes?

You have two ways to access it from your desktop:Create a nodeport type service and then access it via nodeip:nodeport.Use Kubectl port forward and then access it via localhost:forwardedport.

What is HTTP proxy in Kubernetes?

Key HTTPProxy Benefits Safely supports multi-team Kubernetes clusters, with the ability to limit which Namespaces may configure virtual hosts and TLS credentials. Enables including of routing configuration for a path or domain from another HTTPProxy, possibly in another Namespace.

What is Kubelet and kube-proxy?

kubelet – watches the API server for pods on that node and makes sure they are running. cAdvisor – collects metrics about pods running on that particular node. kube-proxy – watches the API server for pods/services changes in order to maintain the network up to date.

Is kube-proxy a load balancer?

The most basic default Kubernetes load balancing strategy in a typical Kubernetes cluster comes from the kube-proxy. The kube-proxy fields all requests that are sent to the Kubernetes service and routes them.

How do you make a Kubernetes dashboard?

Installing Kubernetes DashboardFirst, open your favorite SSH client and connect to your Kubernetes master node.Next, install the Kubernetes dashboard by running the kubectl apply command as shown below. ... Now, verify all of the resources were installed successfully by running the kubectl get command.

Does Kubernetes have a GUI?

Kubernetes Dashboard is the most popular and mature for Kubernetes GUI client. This web UI dashboard gives an overview of applications running on your cluster, as well as for creating or modifying individual Kubernetes resources. Compared to other clients like Lens and Octant, its filtering ability is limited.

How do you get the Minikube dashboard?

20:2230:07Kubernetes Minikube Tutorial Kubernetes Minikube DashboardYouTubeStart of suggested clipEnd of suggested clipUsing a deploy wizard now to access the dashboard you simply use the command mini cube dashboard.MoreUsing a deploy wizard now to access the dashboard you simply use the command mini cube dashboard. And this will enable the dashboard add-on. And open the proxy in the default.

How do I get Kubernetes tokens?

Obtaining the service account token by using kubectlInstall kubectl in your cluster. ... Get the service account token by using kubectl. ... kubectl config set-credentials sa-user --token=$(kubectl get secret -o jsonpath={.data.token} | base64 -d) kubectl config set-context sa-context --user=sa-user.More items...

Where is Kubectl config stored?

Usually the kubectl config file is stored at: $Home/.kube/config in the master node of your remote Kubernetes cluster. This is the config file used by the kubectl utility installed in your remote cluster’s master node.

How does Kubectl CLI work?

The kubectl CLI utility talk s to the Kubernetes cluster via the cluster’s API server. As long as we could make the cluster’s API server accessible from your laptop, we could access or manage your remote Kubernetes cluster or minikube through a local kubectl instance installed on your laptop.

What commands do you use to get pods in Kubernetes?

Next, you could execute any kubectl commands such as ‘kubectl get pod’ or ‘kubectl get service’ from your laptop and the remote API server should respond back with the status of your pods running in your remote Kubernetes cluster or minikube.

How to configure Kubernetes cluster?

You are expected to have a basic understanding on: 1 How to configure and setup a Kubernetes cluster or minikube 2 How to run a Docker container as a Kubernetes deployment and service 3 What kubectl and kubeadm tools are and how they are used for Kubernetes cluster, pod management and orchestration. 4 You have a working Kubernetes Cluster or Minikube setup already.

What is a socketxp gateway?

Moreover, SocketXP VPN Cloud Gateway is an online SaaS service that eliminates the need to run any VPN server in your private cloud or the need to run a VPN client software on your access devices such as laptops.

What is socketxp?

SocketXP assigns you a unique public URL for your server application with random strings in it , that eliminates any guess work for the random Public URL uniquely assigned to you. This adds an additional level of security, in the first place.

Where to find socketxp URL?

Now you can retrieve the SocketXP Public URL created for your Kubernetes API server from the SocketXP Portal Page at: https://portal.socketxp.com/#/tunnels (opens new window) or from the pod logs as shown below.

grafana-service.yaml

apiVersion: v1 kind: Service metadata: namespace: monitoring name: grafana labels: app: grafana spec: type: NodePort ports: - name: web port: 3000 protocol: TCP nodePort: 30902 selector: app: grafana

grafana-deployment.yaml

apiVersion: extensions/v1beta1 kind: Deployment metadata: namespace: monitoring name: grafana spec: replicas: 1 template: metadata: labels: app: grafana spec: containers: - name: grafana image: grafana/grafana:4.1.1 env: - name: GF_AUTH_BASIC_ENABLED value: "true" - name: GF_AUTH_ANONYMOUS_ENABLED value: "true" - name: GF_SECURITY_ADMIN_USER valueFrom: secretKeyRef: name: grafana-credentials key: user - name: GF_SECURITY_ADMIN_PASSWORD valueFrom: secretKeyRef: name: grafana-credentials key: password volumeMounts: - name: grafana-storage mountPath: /var/grafana-storage ports: - name: web containerPort: 3000 resources: requests: memory: 100Mi cpu: 100m limits: memory: 200Mi cpu: 200m - name: grafana-watcher image: quay.io/coreos/grafana-watcher:v0.0.5 args: - '--watch-dir=/var/grafana-dashboards' - '--grafana-url=http://localhost:3000' env: - name: GRAFANA_USER valueFrom: secretKeyRef: name: grafana-credentials key: user - name: GRAFANA_PASSWORD valueFrom: secretKeyRef: name: grafana-credentials key: password resources: requests: memory: "16Mi" cpu: "50m" limits: memory: "32Mi" cpu: "100m" volumeMounts: - name: grafana-dashboards mountPath: /var/grafana-dashboards volumes: - name: grafana-storage emptyDir: {} - name: grafana-dashboards configMap: name: grafana-dashboards.

How to Directly Access the REST API ?

Kubectl is in charge of finding and authenticating the apiserver. In proxy mode, run kubectl.

Using Kubectl Proxy

This command configures kubectl to work as a reverse proxy. It’s in charge of locating and authenticating the apiserver. Assume this scenario:

Without the Use of Kubectl Proxy

To acquire the default service account token, run kubectl describe secret… with grep/cut.

API and the Programmatic Access

It is to announce that Kubernetes now supports Go and Python client libraries. The Go client and python client can utilize the same kubeconfig file as the kubectl CLI to locate and authenticate with the apiserver.

Access the API from a Pod

When contacting the API from a pod, the process of finding and authenticating the apiserver differs slightly. The best way to locate the apiserver in the pod is to use the Kubernetes.default.svc DNS name. It resolves to a Service IP, and it is then, in turn, routed to an apiserver.

Conclusion

Here we have provided guidelines on kubectl proxy. What is the kubectl config view common, and how can you access the REST API with and without Kubectl proxy. We have also provided examples to help you understand the concept better.

How to get Kubeconfig?

For clusters that are created manually using vm's of cloud providers , just get the kubeconfig from ~/.kube/config. However for managed services like GKE you will have to rely on gcloud to get the kubeconfig generated in the runtime with the right token.

What is a service account in Kubeconfig?

Generally a service account can be created that will help in getting the right kubeconfig with token generated for you. Something similar can also be found in Azure.

How does Kubectl work?

Kubectl handles locating and authenticating to the apiserver. If you want to directly access the REST API with an http client like curl or wget, or a browser, there are several ways to locate and authenticate:

What CLI to use for Kubernetes API?

When accessing the Kubernetes API for the first time, we suggest using the Kubernetes CLI, kubectl.

What type of service is used to make a service reachable outside the cluster?

Use a service with type NodePort or LoadBalancer to make the service reachable outside the cluster. See the services and kubectl expose documentation.

How to access a pod from a set of replicas?

To access one specific pod from a set of replicas, such as for debugging, place a unique label on the pod and create a new service which selects this label .

How to authenticate to apiserver?

The recommended way to authenticate to the apiserver is with a service account credential. By kube-system, a pod is associated with a service account, and a credential (token) for that service account is placed into the filesystem tree of each container in that pod, at /var/run/secrets/kubernetes.io/serviceaccount/token.

How to use Python client?

To use Python client, run the following command: pip install kubernetes. See Python Client Library page for more installation options.

Does Go use Kubeconfig?

The Go client can use the same kubeconfig file as the kubectl CLI does to locate and authenticate to the apiserver. See this example.

Step-1 : Install Kubectl in Macbook

You can install Kubectl in Macbook using Homebrew with the following command.

Step-2 : Download Kubernetes Credentials From Remote Cluster

You need to first copy some Kubernetes credentials from remote Kubernetes master to your Macbook.

Step-3 : Copy Kubernetes Credentials To Your Home

Copy the Kubernetes Credentials your downloaded to your home directory as shown below.

What does it mean when you get access denied in KubeConfig?

You'll see an error saying access denied, that's fine. It just shows that we need to get a valid kubeconfig file.

What is the default address for Kubernetes API?

Note that the server has been changed to https://kubernetes.svc.443 which is the default address of the Kubernetes API server within Kubernetes.

What is an inlets-connect proxy?

The inlets-connect proxy is a single-purpose HTTP proxy that can be used instead of turning off TLS verification or updating the Kubernetes API Server's TLS SAN names.

How to get k3sup config?

If you're using k3sup, you can get the config with k3sup install --skip-install --ip $IP --user $USER, which simply reads back a remote KUBECONFIG from K3s using SSH.

What is export port 6443?

Set export PORTS=6443" - the port of the apiserver in Kubernetes

What is inletsctl project?

The inletsctl project automates all of the above, and sets up a systemd unit file for your inlets-pro tcp server process. You can provision tunnel servres on to other clouds, just run inletsctl create --help to see a list of what's available.

Why run inlets-pro tcp?

Run an inlets-pro tcp client in the private cluster to make the proxy available on the server, but only on loopback, to prevent anyone accessing it publicly

image
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 1 2 3 4 5 6 7 8 9