指定命名空间时,Kubernetes Pod无法联系其他Pod
我在centOS 7上使用Kubernetes指定命名空间时,Kubernetes Pod无法联系其他Pod,kubernetes,kubernetes-pod,Kubernetes,Kubernetes Pod,我在centOS 7上使用Kubernetes Client Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.3", GitCommit:"b3cbbae08ec52a7fc73d334838e18d17e8512749", GitTreeState:"clean", BuildDate:"2019-11-13T11:23:11Z", GoVersion:"go1.12.12", Compiler:"gc", Plat
Client Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.3", GitCommit:"b3cbbae08ec52a7fc73d334838e18d17e8512749", GitTreeState:"clean", BuildDate:"2019-11-13T11:23:11Z", GoVersion:"go1.12.12", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.3", GitCommit:"b3cbbae08ec52a7fc73d334838e18d17e8512749", GitTreeState:"clean", BuildDate:"2019-11-13T11:13:49Z", GoVersion:"go1.12.12", Compiler:"gc", Platform:"linux/amd64"}
我确实使用以下prod\u www\u pod.yaml在“生产”名称空间上部署了一个Nginx pod:
apiVersion: v1
kind: Pod
metadata:
name: www
namespace: production
labels:
app: www
spec:
containers:
- name: nginx
image: myrepo:5001/nginx
我部署了第二个(prod_debug.yaml)以检查是否一切正常运行
apiVersion: v1
kind: Pod
metadata:
name: debug
namespace: production
spec:
containers:
- name: debug
image: myrepo:5001/debug:latest
command:
- "sleep"
- "10000"
我可以在正确的名称空间中看到
[plaurent@kubmaster deployment]$ kubectl get po
No resources found in default namespace.
[plaurent@kubmaster deployment]$ kubectl get po -n production
NAME READY STATUS RESTARTS AGE
debug 1/1 Running 0 94s
www 1/1 Running 0 3m57s
但在尝试从调试中卷曲www时,我有:
[plaurent@kubmaster deployment]$ kubectl exec -it -n production debug -- sh
/ # curl www
Nothing there
/ #
在一次kubectl delete-po调试www-n产品之后,我尝试安装相同的程序,只是删除了元数据上指定的名称空间
[plaurent@kubmaster deployment]$ kubectl get po
NAME READY STATUS RESTARTS AGE
debug 1/1 Running 0 10s
www 1/1 Running 0 18s
当尝试通过调试联系www时,它运行良好
[plaurent@kubmaster deployment]$ kubectl exec -it debug -- sh
/ # curl www
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
/ #
[plaurent@kubmaster部署]$kubectl exec-it调试--sh
/#卷曲www
欢迎来到nginx!
身体{
宽度:35em;
保证金:0自动;
字体系列:Tahoma、Verdana、Arial、无衬线字体;
}
欢迎来到nginx!
如果您看到此页面,则nginx web服务器已成功安装,并且
工作需要进一步配置
有关在线文档和支持,请参阅
.
商业支持可从以下网址获得:
感谢您使用nginx
/ #
有人能给我指一下正确的方向吗
问候,
Pierre除非您已经为pod配置了主机名和子域,否则您无法通过dns访问pod,并且访问pod的方式与您现在所做的不同
可能您在默认命名空间中有一个名为www
的服务,该服务正在将请求转发到pod,但在生产命名空间中您没有该服务
要确认我说的话,请在default
和production
名称空间中运行kubectl get svc
如果我是对的,请通过kubectl expose pod…
公开您的pod,或者通过yaml文件创建服务
现在,请注意,创建一个pod是一个坏主意。最好使用1个副本创建e部署。这在默认名称空间中工作,而不是在生产名称空间中工作,因为默认情况下kube dns是如何配置的。这个因此,当使用默认名称空间时,默认值允许kube dns定位www。但是由于production.svc.cluster.local
没有默认条目,因此名称解析失败
您需要配置一个服务以在生产名称空间中公开www pod(也可以使用)。Ty您的建议@suren,就是这样kubectl get svc
没有显示任何内容,我在默认名称空间中有一个www服务。服务是使用yaml文件正确创建的,它在正确的名称空间中运行良好。我还创建了一个带有一个副本的部署yaml文件。