Home > Blockchain >  "The connection to the server localhost:8080 was refused - did you specify the right host or po
"The connection to the server localhost:8080 was refused - did you specify the right host or po

Time:05-22

I'm on an ec2 instance trying to get my cluster created. I have kubectl already installed and here are my services and workloads yaml files

services.yaml

apiVersion: v1
kind: Service
metadata:
  name: stockapi-webapp

spec:
  selector:
    app: stockapi

  ports:
    - name: http
      port: 80

  type: LoadBalancer

workloads.yaml

apiVersion: v1
kind: Deployment
metadata:
  name: stockapi
spec:
  selector:
    matchLabels:
      app: stockapi
  replicas: 1
  template: # template for the pods
    metadata:
      labels:
        app: stockapi
    spec:
      containers:
      - name: stock-api
        image: public.ecr.aws/u1c1h9j4/stock-api:latest

When I try to run

kubectl apply -f workloads.yaml

I get this as an error

The connection to the server localhost:8080 was refused - did you specify the right host or port?

I also tried changing the port in my services.yaml to 8080 and that didn't fix it either

CodePudding user response:

This error comes when you don't have ~/.kube/config file present or configured correctly on the client / where you run the kubectl command.

kubectl reads the clusterinfo and which port to connect to from the ~/.kube/config file.

if you are using eks here's how you can create config file aws eks create kubeconfig file

  • Related