gpt4 book ai didi

amazon-web-services - 如何使用ClusterIP服务将Lambda的GET/POST请求发送到Pod

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

我正在尝试将Lambda的GET请求发送到Pod,而不在外部公开它。该 pods 已附加了ClusterIP服务。我可以直接通过互联网(通过入口)访问此pod,因此我知道它可以正常运行。

这是附加到Pod的服务的一部分:

spec:
clusterIP: 10.xxx.xxx.xx
ports:
- name: http
port: 80
protocol: TCP
targetPort: 8080
selector:
app: app_name
sessionAffinity: None
type: ClusterIP
status:
loadBalancer: {}

我将lambda附加到了vpc和子网,但是如果使用下面的代码,则会出现错误。我尝试使用Pod IP地址和群集IP地址,但存在相同的错误。它适用于Google /其他网站以及Pod暴露于互联网的情况。
    const http = require('http');
exports.handler = async (event, context) => {
return new Promise((resolve, reject) => {
const options = {
host: 'www.google.com',
path: '/api/',
port: 80,
method: 'GET'
};
const req = http.request(options, (res) => {
let data = '';

// A chunk of data has been recieved.
res.on('data', (chunk) => {
data += chunk;
});

// The whole response has been received. Print out the result.
res.on('end', () => {
console.log(JSON.parse(data));
});

});
req.write('');
req.end();
});
};

响应:
{
"errorMessage": "Task timed out after 3.00 seconds"
}

我了解以下所有内容,并且很乐意更改服务类型,但是我不知道该如何处理Lambda中的广告连播(用www.google.com代替)。很高兴尝试其他任何代码或python脚本。
A ClusterIP service is the default Kubernetes service. It gives you a service inside your cluster that other apps inside your cluster can access. There is no external access.

A NodePort service is the most primitive way to get external traffic directly to your service. NodePort, as the name implies, opens a specific port on all the Nodes (the VMs), and any traffic that is sent to this port is forwarded to the service.

A LoadBalancer service is the standard way to expose a service to the internet. On GKE, this will spin up a Network Load Balancer that will give you a single IP address that will forward all traffic to your service.

有人尝试过类似的东西吗?

最佳答案

最简单的方法之一是将服务公开到内部负载均衡器后面。这样,您的服务将不会暴露于Internet,但仍可在VPC中使用。

apiVersion: v1
kind: Service
metadata:
name: my-service
annotations:
service.beta.kubernetes.io/aws-load-balancer-internal: 0.0.0.0/0
spec:
type: LoadBalancer
selector:
app: MyApp
ports:
- protocol: TCP
port: 80
targetPort: 80

更高级但更灵活的解决方案是将 Nginx Ingress与相同的内部负载均衡器一起使用。

关于amazon-web-services - 如何使用ClusterIP服务将Lambda的GET/POST请求发送到Pod,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56040428/

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