【问题标题】:"The connection to the server localhost:8080 was refused - did you specify the right host or port?"\"与服务器 localhost:8080 的连接被拒绝 - 您是否指定了正确的主机或端口?\"
【发布时间】:2022-08-22 07:42:17
【问题描述】:

我正在尝试创建集群的 ec2 实例。我已经安装了 kubectl,这是我的服务和工作负载 yaml 文件

服务.yaml

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

spec:
  selector:
    app: stockapi

  ports:
    - name: http
      port: 80

  type: LoadBalancer

工作负载.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

当我尝试跑步时

kubectl apply -f workloads.yaml

我认为这是一个错误

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

我还尝试将我的 services.yaml 中的端口更改为 8080,但这也没有解决它

    标签: kubernetes amazon-eks


    【解决方案1】:

    当您在运行kubectl 命令的客户端上/没有正确配置~/.kube/config 文件时,就会出现此错误。

    kubectl 从~/.kube/config 文件中读取集群信息和连接的端口。

    如果您使用的是 eks,请按照以下说明创建 config 文件 aws eks create kubeconfig file

    【讨论】:

      【解决方案2】:

      我按照aws 上的说明进行操作

      和我一起,我在Mac上。我安装了 docker 桌面。这似乎在自制软件中包含了 kubectl

      我将其追溯到usr/local/bin 中的链接并将其重命名为kubectl-old

      然后我重新安装了 kubectl,把它放在我的路径上,一切正常。

      我知道这对我的情况非常具体,但可能对其他人有所帮助。

      【讨论】:

        猜你喜欢
        • 2018-12-09
        • 2019-06-01
        • 1970-01-01
        • 2018-12-03
        • 2019-09-25
        • 2021-05-05
        • 2018-12-18
        • 2021-03-16
        • 2020-02-25
        相关资源
        最近更新 更多