【发布时间】:2017-03-29 18:27:54
【问题描述】:
我想访问外部服务/API
喜欢调用维基百科,所以我需要端口 80 http://en.wikipedia.org/w/api.php?action=opensearch&search=bee&limit=1&format=json
我的应用程序位于容器内的 pod 中,我暴露了端口 8000 并将其绑定到服务类型 loadbalncer 中的 300。
还可以访问托管在 kubernetes 之外的外部数据库,比如 mysql,所以我需要端口 3306,如何做到这一点。
这些都是部署文件和服务文件
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: request-wiki-deployment
spec:
replicas: 2
template:
metadata:
labels:
app: request-wiki
spec:
containers:
- name: request-wiki
image: hadyrashwan/request-wiki:0.0.4
imagePullPolicy: Always
ports:
- containerPort: 8000
- containerPort: 80
https://github.com/hadyrashwan/request-wiki/blob/feature/open-internal-80/wiki-request-service.yaml
apiVersion: v1
kind: Service
metadata:
labels:
name: request-wiki
name: request-wiki-service
spec:
selector:
app: request-wiki
ports:
# - name: app
- port: 3000
protocol: TCP
targetPort: 8000
# - name: app
# protocol: TCP
# targetPort: 80
type: LoadBalancer
仍然没有使用配置/秘密或 tls
我在 2 台主机上使用 Rancher,用于 Kubernetes 环境,一台在 GCP 上,另一台在 AWS 上
【问题讨论】:
-
问题是什么?您无法从 pod 内部访问外部服务?你遇到了什么错误?
-
yes { 错误:getaddrinfo EAI_AGAIN en.wikipedia.org:443 at Object.exports._errnoException (util.js:1034:11) at errnoException (dns.js:33:15) at GetAddrInfoReqWrap。 onlookup [as oncomplete] (dns.js:73:26) 代码:'EAI_AGAIN',errno:'EAI_AGAIN',系统调用:'getaddrinfo',主机名:'en.wikipedia.org',主机:'en.wikipedia.org ',端口:443 }
标签: mysql docker kubernetes rancher