You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Vagrant provision阶段kubectl连接localhost:8080失败,ssh执行正常

问题:Vagrant Provision执行kubectl时连接被拒绝,手动执行正常

环境与操作步骤

  • 使用Vagrant部署Kubernetes,基于对应的Vagrantfile模板
  • 在node节点的provision配置段中,于node.vm.provision "shell", path: "scripts/node.sh"之后添加了自定义shell脚本配置:
    node.vm.provision "shell", path: "ecoemploi_scripts/ecoemploi-create.sh"
    
  • 自定义脚本ecoemploi_scripts/ecoemploi-create.sh的内容如下:
    echo "Création du déploiement Kubernetes pour ecoemploi"
    kubectl apply -f ecoemploi-namespace.yaml
    kubectl apply -f ecoemploi-postgis-configmap.yaml
    kubectl apply -f ecoemploi-postgis-pv-pvclaim.yaml
    
    kubectl apply -f ecoemploi-postgis-sgbd.yaml
    kubectl apply -f ecoemploi-postgis-service.yaml
    

执行vagrant up时的错误

启动过程中node01节点输出以下错误:

node01: Création du déploiement Kubernetes pour ecoemploi
node01: The connection to the server localhost:8080 was refused - did you specify the right host or port?
node01: The connection to the server localhost:8080 was refused - did you specify the right host or port?
node01: The connection to the server localhost:8080 was refused - did you specify the right host or port?
node01: The connection to the server localhost:8080 was refused - did you specify the right host or port?
node01: The connection to the server localhost:8080 was refused - did you specify the right host or port?

手动执行命令正常

通过vagrant ssh node01登录节点后,手动执行相同命令可成功完成部署:

vagrant@worker-node01:~$ kubectl apply -f /vagrant/ecoemploi_scripts/ecoemploi-namespace.yaml
namespace/ecoemploi created
vagrant@worker-node01:~$ kubectl apply -f /vagrant/ecoemploi_scripts/ecoemploi-postgis-configmap.yaml 
configmap/postgres-config created
vagrant@worker-node01:~$ kubectl apply -f /vagrant/ecoemploi_scripts/ecoemploi-postgis-pv-pvclaim.yaml 
persistentvolume/postgres-pv-volume created
persistentvolumeclaim/postgres-pv-claim created
vagrant@worker-node01:~$ kubectl apply -f /vagrant/ecoemploi_scripts/ecoemploi-postgis-service.yaml 
service/postgres created
vagrant@worker-node01:~$ kubectl apply -f /vagrant/ecoemploi_scripts/ecoemploi-postgis-sgbd.yaml 
deployment.apps/postgres created

kubectl get all -n ecoemploi
NAME                           READY   STATUS    RESTARTS   AGE
pod/postgres-5698988bf-npw9j   1/1     Running   0          27s

NAME               TYPE       CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
service/postgres   NodePort   172.17.52.216   <none>        5432:32187/TCP   40s

NAME                       READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/postgres   1/1     1            1           27s

NAME                                 DESIRED   CURRENT   READY   AGE
replicaset.apps/postgres-5698988bf   1         1         1       27s

疑问

已尝试修改脚本中的文件路径为绝对路径或相对路径,但问题依旧。请问操作过程中哪里出现了错误?


内容的提问来源于stack exchange,提问作者Marc Le Bihan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 04:52:43