【发布时间】:2021-10-20 17:07:41
【问题描述】:
我正在使用 GKE 完成一个 kubernetes 教程,但它是在考虑 Azure 的情况下编写的 - 尽管到目前为止它运行正常。
它没有起作用的第一部分是关于 coreDNS 的练习——据我所知,这在 GKE 上不存在——它只是 kubedns?
这就是为什么我无法获得 pod 端点的原因:
export PODIP=$(kubectl get endpoints hello-world-clusterip -o jsonpath='{ .subsets[].addresses[].ip}')
然后卷曲:
curl http://$PODIP:8080
我的部署肯定是在正确的端口上:
ports:
- containerPort: 8080
事实上,tut 的部署来自 google 示例。
这与 coreDNS 或授权/需要服务帐户有关吗?我该怎么做才能使 curl 请求正常工作?
部署yaml是:
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-world-customdns
spec:
replicas: 3
selector:
matchLabels:
app: hello-world-customdns
template:
metadata:
labels:
app: hello-world-customdns
spec:
containers:
- name: hello-world
image: gcr.io/google-samples/hello-app:1.0
ports:
- containerPort: 8080
dnsPolicy: "None"
dnsConfig:
nameservers:
- 9.9.9.9
---
apiVersion: v1
kind: Service
metadata:
name: hello-world-customdns
spec:
selector:
app: hello-world-customdns
ports:
- port: 80
protocol: TCP
targetPort: 8080
【问题讨论】:
-
您在哪里运行
curl命令?集群 IP 将仅在集群本身内可用。你可以发布你的整个服务 yaml 吗?你在用type: NodePort吗? -
连接到集群后,我正在 gcloud shell 中运行 curl 命令。所有其他 kubectl 命令都有效吗?
-
为了能够通过 Cloud Shell 进行连接,您需要使用负载均衡器服务或 NodePort 服务,以使端点可以在集群本身之外访问。您也可以执行到容器中,或者部署一个睡眠容器并执行到其中。 kubectl 在连接到可路由的 API 端点时工作。我在移动设备上回答,但是一旦回到我的电脑前,我会在答案中发布更多细节。并感谢 YAML。这有帮助。
-
这里是这个复数图的另一个例子:kubectl create deployment hello-world-nodeport --image=gcr.io/google-samples/hello-app:1.0 kubectl expose deployment hello-world-nodeport - -port=80 --target-port=8080 --type NodePort export NODEPORT=$(kubectl get service hello-world-nodeport -o jsonpath='{ .spec.ports[].nodePort }') 然后我得到我的 pod命名并运行 curl http://$PODNAME:$NODEPORT 会超时吗?
-
您可以查看此document,了解如何在 GKE 中部署和公开服务的一个很好的示例,同时强调 @GariSingh 指出的内容,Service Networking 上有一个很棒的文档,您可以在其中看看暴露服务的理论。
标签: kubernetes google-kubernetes-engine