gpt4 book ai didi

curl - 从Kubernetes Pod到ExternalName服务的cURL挂起

转载 作者:行者123 更新时间:2023-12-02 12:22:26 24 4
gpt4 key购买 nike

问题:我尝试从临时busybox容器内的ExternalName服务上执行cURL,但是 call 只是挂起。如果我对外部名称而不是服务名称执行相同的cURL,则它可以工作。

以下是服务yaml:

apiVersion: v1
kind: Service
metadata:
name: google
spec:
type: ExternalName
externalName: google.com

我使用 kubectl create -f创建服务,然后创建一个临时的交互式busybox pod:
kubectl run -i --tty busybox --image=sequenceiq/busybox --restart=Never -- sh

从中我执行以下cURL:
/ # curl google #hangs, have to interrupt
^C
/ # curl google.com

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="http://www.google.de/?gfe_rd=cr&amp;ei=SQWDWYXTNZGg8wfFlIGQDw">here</A>.
</BODY></HTML>

因此,一个显而易见的问题是:为什么第一个cURL挂起,而第二个cURL却没有挂起,考虑到 google只是 google.com的CNAME,正如下面的 host输出(从交互式busybox执行)所证实的那样?
/ # host google
google.default.svc.cluster.local is an alias for google.com.
google.com has address 172.217.18.174
google.com has IPv6 address 2a00:1450:4001:806::200e
google.com mail is handled by 10 aspmx.l.google.com.
google.com mail is handled by 40 alt3.aspmx.l.google.com.
google.com mail is handled by 50 alt4.aspmx.l.google.com.
google.com mail is handled by 20 alt1.aspmx.l.google.com.
google.com mail is handled by 30 alt2.aspmx.l.google.com.

以下是hanging cURL命令的详细输出
/ # curl -vvv google
> GET / HTTP/1.1
> User-Agent: curl/7.38.0
> Host: google
> Accept: */*
>

描述服务的输出(不可能输出为yaml):
$ kubectl describe svc google
Name: google
Namespace: default
Labels: <none>
Annotations: <none>
Selector: <none>
Type: ExternalName
IP:
External Name: google.com
Session Affinity: None
Events: <none>

最佳答案

您将需要在curl命令中设置主机头

$ curl -I google -H 'Host:google.com'
HTTP/1.1 301 Moved Permanently
Location: http://www.google.com/
Content-Type: text/html; charset=UTF-8
Date: Mon, 30 Dec 2019 03:49:12 GMT
Expires: Wed, 29 Jan 2020 03:49:12 GMT
Cache-Control: public, max-age=2592000
Server: gws
Content-Length: 219
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN

关于curl - 从Kubernetes Pod到ExternalName服务的cURL挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45482750/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com