0

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 ?

devcodes
  • 1,038
  • 19
  • 38

1 Answers1

1

"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.

Audun Nes
  • 124
  • 5
  • I can see in kube config file , this cluster server is set as following -> `cluster: server: https://127.0.0.1:6443` You mean I shall change it to just :6443 ? or replace the ip with some other ip address ? – devcodes Nov 24 '22 at 12:10
  • No, this is set during installation. There are many different implementations of Kubernetes. k0s, k3s, k3d, minikube, kind etc are just some of them. I assume you will have to look into the install documentation for your Kubernetes implementation to see how the node name can be set during installation. – Audun Nes Nov 24 '22 at 12:16
  • For my test , I had to test any outgoing connection , I ended up pinging google at 8.8.8.8 443 from my job , will keep this in mind for future , thanks for your answer. – devcodes Nov 24 '22 at 15:31