Kubernetes服务ExternalName [英] Kubernetes Service ExternalName

查看:126
本文介绍了Kubernetes服务ExternalName的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Kubernetes ExternalName Service时遇到了一些问题.我想从群集访问服务器'dummy.restapiexample.com'.我创建了以下服务:

I have some problems with Kubernetes ExternalName Service. I want to access server 'dummy.restapiexample.com' from the cluster . I created the following service:

apiVersion: v1
kind: Service
metadata:
   name: dummy-svc
spec:
    type: ExternalName
    externalName: dummy.restapiexample.com   

$ kubectl get svc
NAME         TYPE           CLUSTER-IP   EXTERNAL-IP                PORT(S)   AGE
dummy-svc    ExternalName   <none>       dummy.restapiexample.com   <none>    33m
kubernetes   ClusterIP      100.64.0.1   <none>                     443/TCP   6d19h

但是当我尝试从同一名称空间的pod访问服务时,我得到的代码是HTTP 403.

But when I try to access the service from a pod from the same namespace, I'm getting code HTTP 403.

$ curl -v http://dummy-svc/api/v1/employee/1
> GET /api/v1/employee/1 HTTP/1.1
> User-Agent: curl/7.35.0
> Host: dummy-svc
> Accept: */*
>
< HTTP/1.1 403 Forbidden
< Content-Type: text/plain
< Date: Sat, 23 Nov 2019 14:21:05 GMT 
< Content-Length: 9
<

我可以访问外部服务器而没有任何问题:

I can access the external server w/o any problem:

$ curl -v http://dummy.restapiexample.com/api/v1/employee/1                               │
> GET /api/v1/employee/1 HTTP/1.1 
> User-Agent: curl/7.35.0 
> Host: dummy.restapiexample.com
> Accept: */*                                                                                            
< HTTP/1.1 200 OK 
...
< Content-Length: 104
{"id":"1","employee_name":"56456464646","employee_salary":"2423","employee_age":"23","profile_image":""}

我的代码有什么问题?任何提示将不胜感激.该集群在AWS上运行,并安装了kops.

What is wrong with my code? Any hint will be highly appreciated.The cluster is runnung on AWS and installed with kops.

推荐答案

正如Patrik W指出的那样,该服务可以正常工作.它将请求路由到远程服务器.Ping到达远程服务器:

As pointed by Patrik W, the service works correctly. It routes requests to the remote server. Ping reaches the remote server:

$ ping dummy-svc

PING dummy.restapiexample.com (52.209.246.67) 56(84) bytes of data.
64 bytes from ec2-52-209-246-67.eu-west-1.compute.amazonaws.com (52.209.246.67): icmp_seq=1 ttl=62 time=1.29 ms

由于网址不同,从远程服务器收到的代码403.

Code 403 received from the remote server because of different URLs.

@Patrik W:谢谢您的帮助.

@Patrik W: Thanks for the help.

这篇关于Kubernetes服务ExternalName的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆