我正在使用https://github.com/techiescamp/vagrant-kubeadm-kubernetes/blob/main/Vagrantfile模型将 Kubernetes 部署到VM中。
在其node
部分的末尾,就在
node.vm.provision "shell", path: "scripts/node.sh"
我加了一个
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: 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-
ecoemploi-postgis-configmap.yaml ecoemploi-postgis-pv-pvclaim.yaml ecoemploi-postgis-service.yaml ecoemploi-postgis-sgbd.yaml
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
所以,我修改了我的脚本:
echo "Création du déploiement Kubernetes pour ecoemploi"
kubectl apply -f /vagrant/ecoemploi_scripts/ecoemploi-namespace.yaml
kubectl apply -f /vagrant/ecoemploi_scripts/ecoemploi-postgis-configmap.yaml
kubectl apply -f /vagrant/ecoemploi_scripts/ecoemploi-postgis-pv-pvclaim.yaml
kubectl apply -f /vagrant/ecoemploi_scripts/ecoemploi-postgis-sgbd.yaml
kubectl apply -f /vagrant/ecoemploi_scripts/ecoemploi-postgis-service.yaml
或
kubectl apply -f ecoemploi_scripts/ecoemploi-namespace.yaml
kubectl apply -f ecoemploi_scripts/ecoemploi-postgis-configmap.yaml
[...]
但还是失败了
我做错了什么?
1条答案
按热度按时间vawmfj5a1#
我找到答案了
是我写剧本的好方法
但是,它必须作为普通的
vagrant
用户执行,以确保 Kubernetes 首先以正常的方式启动。