Kubernetes-服务总是命中同一个吊舱容器
我有一个基于Docker桌面的本地Kubernetes安装。 我有一个Kubernetes服务设置,集群IP位于3个吊舱之上。 我注意到当查看容器日志时,同一个吊舱总是被击中 这是群集IP的默认行为吗? 如果是这样的话,其他POD将如何使用,或者它们使用集群IP有什么意义 另一个选项是使用LoadBalancer类型,但是我希望该服务只能从集群中访问 有没有办法使LoadBalancer内部化 如果有人能提供建议,我们将不胜感激 更新: 我试过使用负载平衡器类型,同一个吊舱也一直被击中 这是我的配置:Kubernetes-服务总是命中同一个吊舱容器,kubernetes,kubernetes-service,Kubernetes,Kubernetes Service,我有一个基于Docker桌面的本地Kubernetes安装。 我有一个Kubernetes服务设置,集群IP位于3个吊舱之上。 我注意到当查看容器日志时,同一个吊舱总是被击中 这是群集IP的默认行为吗? 如果是这样的话,其他POD将如何使用,或者它们使用集群IP有什么意义 另一个选项是使用LoadBalancer类型,但是我希望该服务只能从集群中访问 有没有办法使LoadBalancer内部化 如果有人能提供建议,我们将不胜感激 更新: 我试过使用负载平衡器类型,同一个吊舱也一直被击中 这是我的
apiVersion: v1
kind: Namespace
metadata:
name: dropshippingplatform
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: organisationservice-deployment
namespace: dropshippingplatform
spec:
selector:
matchLabels:
app: organisationservice-pod
replicas: 3
template:
metadata:
labels:
app: organisationservice-pod
spec:
containers:
- name: organisationservice-container
image: organisationservice:v1.0.1
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: organisationservice-service
namespace: dropshippingplatform
spec:
selector:
app: organisationservice-pod
ports:
- protocol: TCP
port: 81
targetPort: 80
type: LoadBalancer
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: apigateway-deployment
namespace: dropshippingplatform
spec:
selector:
matchLabels:
app: apigateway-pod
template:
metadata:
labels:
app: apigateway-pod
spec:
containers:
- name: apigateway-container
image: apigateway:v1.0.1
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: apigateway-service
namespace: dropshippingplatform
spec:
selector:
app: apigateway-pod
ports:
- protocol: TCP
port: 80
targetPort: 80
type: LoadBalancer
以下是我的Ocelot配置:
{
"Routes": [
{
"DownstreamPathTemplate": "/api/organisations",
"DownstreamScheme": "http",
"ServiceName": "organisationservice-service",
"ServiceNamespace": "dropshippingplatform",
"UpstreamPathTemplate": "/APIGateway/Organisations",
"UpstreamHttpMethod": [ "Get" ],
"Key": "Login"
},
{
"DownstreamPathTemplate": "/weatherforecast",
"DownstreamScheme": "http",
"ServiceName": "organisationservice-service",
"ServiceNamespace": "dropshippingplatform",
"UpstreamPathTemplate": "/APIGateway/WeatherForecast",
"UpstreamHttpMethod": [ "Get" ],
"Key": "WeatherForecast"
}
],
"Aggregates": [
{
"RouteKeys": [
"Login",
"WeatherForecast"
],
"UpstreamPathTemplate": "/APIGateway/Organisations/Login"
},
{
"RouteKeys": [
"Login",
"WeatherForecast"
],
"UpstreamPathTemplate": "/APIGateway/Organisations/TestAggregator",
"Aggregator": "TestAggregator"
}
],
"GlobalConfiguration": {
"ServiceDiscoveryProvider": {
"Namespace": "default",
"Type": "KubernetesServiceDiscoveryProvider"
}
}
}
"LoadBalancerOptions": {
"Type": "RoundRobin"
},
为了隔离这个问题,我在所讨论的Kubernetes服务前面创建了一个负载平衡器,并直接从客户端调用该服务。同一个吊舱一直被击中,这告诉我这与Kubernetes有关,而不是Ocelot API网关
以下是kubectl Descripte svc的输出:
Name: organisationservice-service
Namespace: dropshippingplatform
Labels: <none>
Annotations: <none>
Selector: app=organisationservice-pod
Type: ClusterIP
IP: X.X.X.119
Port: <unset> 81/TCP
TargetPort: 80/TCP
Endpoints: X.X.X.163:80,X.X.X.165:80,X.X.X.166:80
Session Affinity: None
Events: <none>
名称:组织服务
名称空间:dropshippingplatform
标签:
注释:
选择器:app=组织服务吊舱
类型:集群
IP:X.X.X.119
端口:81/TCP
目标端口:80/TCP
终点:X.X.X.163:80,X.X.X.165:80,X.X.X.166:80
会话关联:无
活动:
我解决了它。事实证明,Ocelot API网关就是问题所在。我在Ocelot配置中添加了以下内容:
{
"Routes": [
{
"DownstreamPathTemplate": "/api/organisations",
"DownstreamScheme": "http",
"ServiceName": "organisationservice-service",
"ServiceNamespace": "dropshippingplatform",
"UpstreamPathTemplate": "/APIGateway/Organisations",
"UpstreamHttpMethod": [ "Get" ],
"Key": "Login"
},
{
"DownstreamPathTemplate": "/weatherforecast",
"DownstreamScheme": "http",
"ServiceName": "organisationservice-service",
"ServiceNamespace": "dropshippingplatform",
"UpstreamPathTemplate": "/APIGateway/WeatherForecast",
"UpstreamHttpMethod": [ "Get" ],
"Key": "WeatherForecast"
}
],
"Aggregates": [
{
"RouteKeys": [
"Login",
"WeatherForecast"
],
"UpstreamPathTemplate": "/APIGateway/Organisations/Login"
},
{
"RouteKeys": [
"Login",
"WeatherForecast"
],
"UpstreamPathTemplate": "/APIGateway/Organisations/TestAggregator",
"Aggregator": "TestAggregator"
}
],
"GlobalConfiguration": {
"ServiceDiscoveryProvider": {
"Namespace": "default",
"Type": "KubernetesServiceDiscoveryProvider"
}
}
}
"LoadBalancerOptions": {
"Type": "RoundRobin"
},
现在它平均分配流量。有很多不同的客户端吗?有没有什么关系?什么类型的网关?您如何连接到该服务?客户端在哪里运行?什么是客户机?只有一个客户机也在本地计算机上运行。但是,我遇到问题的服务不是由客户端调用的,而是一个API网关服务,配置中有详细说明。此API网关正在运行Ocelot。我还将添加Ocelot配置。您好@SachK,您可以添加更多关于您的服务的详细信息吗?命令的结果是什么:
kubectl description svc | grep-i end
和kubectl get ep
。你应该检查端点。请将此信息添加到问题中。您还可以阅读更多内容。@Mikolaj Glodziak-添加了输出