Home > Net >  telnet: Unable to connect to remote host: Connection refused - running from a kubernetes pod
telnet: Unable to connect to remote host: Connection refused - running from a kubernetes pod

Time:11-25

My local kubernetes cluster is running by Rancher Desktop -

% kubectl cluster-info

Kubernetes control plane is running at https://127.0.0.1:6443
CoreDNS is running at https://127.0.0.1:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
Metrics-server is running at https://127.0.0.1:6443/api/v1/namespaces/kube-system/services/https:metrics-server:https/proxy

I have created a very basic job - to do a telnet at localhost and port 6443 and see if the connection is reachable by the job pod running in the cluster ->

apiVersion: batch/v1
kind: Job
metadata:
  name: telnet-test
spec:
  template:
    spec:
      containers:
      - name: test-container
        image: getting-started:latest
        imagePullPolicy: IfNotPresent
        command: ["/usr/bin/telnet"]
        args: ["127.0.0.1","6443"]
      restartPolicy: Never
  backoffLimit: 4

Docker image is also basic , installing telnet ->

#Download base image ubuntu 16.04
FROM ubuntu:16.04

# Update Software repository
RUN apt update && apt upgrade

# Install nginx, php-fpm and supervisord from ubuntu repository
RUN apt install -y telnet

CMD ["which","telnet"]

EXPOSE 6443

When I run this job , I get connection refused ->

telnet: Unable to connect to remote host: Connection refused
Trying 127.0.0.1...

Any idea what I could be missing here ?

CodePudding user response:

"kubectl cluster-info" shows you on which NODE and port your Kubernetes api-server is Running. So these are processes running on either a virtual machine or on a physical machine.

IP address 127.0.0.1 is also known as the localhost address, and belong to the local network adapter. Hence it is NOT a real IP that you can call from any other machine.

When you test 127.0.0.1:6443 inside your container image running as a Pod or with "docker run", you are not trying to call the NODE on port 6443. Instead you are trying to call the localhost address on port 6443 INSIDE the container.

When you install Kubernetes, it would be better if you configure the cluster address as the :6443 or :6443 instead of using a localhost address.

  • Related