Home > Enterprise >  how to access pods from host?
how to access pods from host?

Time:01-16

I'm running colima with kubernetes like: colima start --kuberenetes

I created a few running pods, and I want to see access the through the browsers. But I don't know what is the colima IP (or kubernetes node IP).

help appreciated

CodePudding user response:

You can get the nodeIp so:

kubectl get node

NAME       STATUS   ROLES    AGE   VERSION
nodeName   Ready    <none>   15h   v1.26.0

Then with the nodeName:

kubectl describe node nodeName

That gives you a descrition of the node and you should look for this section:

Addresses:
  InternalIP:  10.165.39.165
  Hostname:    master

Ping it to verify the network.

Find your host file on Mac and make an entry like:

10.165.39.165 test.local

This let you access the cluster with a domain name.

Ping it to verify.

You can not access from outside the cluster a ClusterIp. To access your pod you have several possibilities.

  1. if your service is type ClusterIp, you can create a temporary connection from your host with a port forward.
kubectl port-forward svc/yourservicename localport:podport
  1. (i would raccomend this) create a service type: NodePort

Then

kubectl get svc -o wide

Shows you the NodePort: between(30000-32000).

You can access now the Pod by: test.local:nodePort or Ipaddress:NodePort.

Note: If you deployed in a namespace other than default, add -n yournamespace in the kubectl commands.

Update:

if you want to start colima with an ipAddress, first find one of your local network which is available.

Your network setting you can get with:

ifconfig

find the network. Should be the same of that of your Internet router.

Look for the subnet. Most likely 255.255.255.0.

The value to pass then:

  --network-address xxx.xxx.xxx.xxx/24

In case the subnet is 255.255.0.0 then /16. But i dont think, if you are connect from home. Inside a company however this is possible.

Again check with ping and follow the steps from begining to verify the kubernetes node configuration.

CodePudding user response:

There are a few ways to access pods from a node. Here are a couple of options:

  1. Using kubectl port-forward: This command allows you to forward a local port to a port on the pod. For example, if you want to access a web application running on port 8080 in the pod, you can run kubectl port-forward <pod-name> 8080:8080 and then access the application by visiting http://localhost:8080 in your browser.

  2. Using kubectl expose: This command creates a service that exposes a specific pod to the network. Once the service is created, you can use kubectl get svc to find the IP address of the service, and then access the pod by visiting the IP address in the browser.

  3. Using kubectl get nodes to get the IP address of your Kubernetes nodes, and then you can use the kubectl describe pod <pod-name> to find the port of the pod you want to access and use that IP and port to connect to the pod.

  4. Using kubectl apply -f command to create an Ingress resource. Once the ingress is created, you can use kubectl get ingress <ingress-name> to find the IP address and hostname of the ingress, and then access the pods by visiting the IP address or hostname in the browser.

Please note that depending on your cluster setup, some of the above options may not be available.

Also, please note that pods are not intended to be accessed directly and are usually exposed to the network through Services, and Ingresses, so it's recommended to use them instead.

  • Related