处理具有多个容器的单个 pod
Handling a single pod with multiple container
我需要将多容器设置转换为具有多个容器的单个容器。我有 pod x 运行 x 微服务和 pod y 运行 y 具有以下 rest 端点的微服务。
http://x:8080/{context path-x}/endpoint
http://y:8080/{context path-y}/endpoint
我想要 pod z 和 x 和 y 微服务,容器 x 暴露在 8080 端口上,y 暴露在同一个 pod 的 8081 上。我能够通过多容器 pod 实现这些。
我的问题是 URL 已更改
http://z:8080/{context path-x}/endpoint
http://z:8081/{context path-y}/endpoint
我正在寻找可以在不更改 URL 或低于 URLs
的情况下达到终点的方法
http://x:8080/{context path-x}/endpoint
http://y:8081/{context path-y}/endpoint
我的真实项目要求在单个 pods 上有 5 个容器,并且暴露了 100 个端点
我怎样才能做到这一点?
K8s 服务是公开您的应用程序的方式。由于您有两个应用程序,并希望将它们 运行 作为单个 Pod 中的两个不同容器,并且您希望对应用程序进行最少的更改 API URL,那么只需创建两个不同的服务即可目标港口。因此,您需要在应用程序的 APP url.
中进行 0 次更改
在K8s集群中,您可以简单地使用服务名称作为来自同一命名空间的主机名。可以看到FQDN (fully qualified domain name) convention for a service.
因此,您可以创建两个名称为 x
和 y
的服务,其中 x
的端口为 8080,y
的端口为 8081。因此您可以使用与以前相同的 urls。
NOTE: There may exist different ways to achieve one's goal(s) but may arise different issues.
以下是我解决问题的方法:
应用程序部署文件(部署 z 上的 x 和 y 容器)
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: z
spec:
replicas: 1
progressDeadlineSeconds: 600
selector:
matchLabels:
component: z
template:
metadata:
annotations:
version: v1.0
labels:
component: z
occloud.oracle.com/open-network-policy: allow
name: z
spec:
containers:
- name: x
image:x:dev
ports:
- containerPort: 8080
- name: y
image: y:dev
ports:
- containerPort: 8081
---
kind: Service
apiVersion: v1
metadata:
name: x
annotations:
version: v1.0
spec:
selector:
component: z
ports:
- name: x
port: 8080
targetPort: 8080
type: ClusterIP
---
kind: Service
apiVersion: v1
metadata:
name: y
annotations:
version: v1.0
spec:
selector:
component: z
ports:
- name: y
port: 8080
targetPort: 8081
type: ClusterIP
http://x:8080/{上下文路径-x}/endpoint
http://y:8080/{上下文路径-y}/endpoint
我需要将多容器设置转换为具有多个容器的单个容器。我有 pod x 运行 x 微服务和 pod y 运行 y 具有以下 rest 端点的微服务。
http://x:8080/{context path-x}/endpoint
http://y:8080/{context path-y}/endpoint
我想要 pod z 和 x 和 y 微服务,容器 x 暴露在 8080 端口上,y 暴露在同一个 pod 的 8081 上。我能够通过多容器 pod 实现这些。
我的问题是 URL 已更改
http://z:8080/{context path-x}/endpoint
http://z:8081/{context path-y}/endpoint
我正在寻找可以在不更改 URL 或低于 URLs
的情况下达到终点的方法http://x:8080/{context path-x}/endpoint
http://y:8081/{context path-y}/endpoint
我的真实项目要求在单个 pods 上有 5 个容器,并且暴露了 100 个端点
我怎样才能做到这一点?
K8s 服务是公开您的应用程序的方式。由于您有两个应用程序,并希望将它们 运行 作为单个 Pod 中的两个不同容器,并且您希望对应用程序进行最少的更改 API URL,那么只需创建两个不同的服务即可目标港口。因此,您需要在应用程序的 APP url.
中进行 0 次更改在K8s集群中,您可以简单地使用服务名称作为来自同一命名空间的主机名。可以看到FQDN (fully qualified domain name) convention for a service.
因此,您可以创建两个名称为 x
和 y
的服务,其中 x
的端口为 8080,y
的端口为 8081。因此您可以使用与以前相同的 urls。
NOTE: There may exist different ways to achieve one's goal(s) but may arise different issues.
以下是我解决问题的方法:
应用程序部署文件(部署 z 上的 x 和 y 容器)
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: z
spec:
replicas: 1
progressDeadlineSeconds: 600
selector:
matchLabels:
component: z
template:
metadata:
annotations:
version: v1.0
labels:
component: z
occloud.oracle.com/open-network-policy: allow
name: z
spec:
containers:
- name: x
image:x:dev
ports:
- containerPort: 8080
- name: y
image: y:dev
ports:
- containerPort: 8081
---
kind: Service
apiVersion: v1
metadata:
name: x
annotations:
version: v1.0
spec:
selector:
component: z
ports:
- name: x
port: 8080
targetPort: 8080
type: ClusterIP
---
kind: Service
apiVersion: v1
metadata:
name: y
annotations:
version: v1.0
spec:
selector:
component: z
ports:
- name: y
port: 8080
targetPort: 8081
type: ClusterIP
http://x:8080/{上下文路径-x}/endpoint http://y:8080/{上下文路径-y}/endpoint