gpt4 book ai didi

docker - 具有多个容器的容器上具有多个裸露端口的单一服务

转载 作者:行者123 更新时间:2023-12-02 11:35:27 32 4
gpt4 key购买 nike

我已经在同一个 pods 中使用了多个容器。

 kubectl apply  -f myymlpod.yml

kubectl expose pod mypod --name=myname-pod --port 8855 --type=NodePort

然后我就可以测试“暴露”
minikube service list

..
|-------------|-------------------------|-----------------------------|
| NAMESPACE | NAME | URL |
|-------------|-------------------------|-----------------------------|
| default | kubernetes | No node port |
| default | myname-pod | http://192.168.99.100:30036 |
| kube-system | kube-dns | No node port |
| kube-system | kubernetes-dashboard | No node port |
|-------------|-------------------------|-----------------------------|

现在,myymlpod.yml中有多个容器。
一个容器的服务在8855上运行,一个在8877。

下面的文章〜提示〜我需要做什么。

https://www.mirantis.com/blog/multi-container-pods-and-container-communication-in-kubernetes/

Exposing multiple containers in a Pod

While this example shows how to use a single container to access other containers in the pod, it’s quite common for several containers in a Pod to listen on different ports — all of which need to be exposed. To make this happen, you can either create a single service with multiple exposed ports, or you can create a single service for every poirt you’re trying to expose.



“创建具有多个公开端口的单一服务”

我找不到任何有关如何实际执行此操作的信息,它公开了多个端口。

如何在一项服务上公开多个端口?

谢谢。

附加:

K8Containers.yml(如下)
apiVersion: v1
kind: Pod
metadata:
name: mypodkindmetadataname
labels:
example: mylabelname

spec:

containers:

- name: containername-springbootfrontend
image: mydocker.com/webfrontendspringboot:latest
resources:
limits:
memory: "800Mi"
cpu: "800m"
requests:
memory: "612Mi"
cpu: "400m"
ports:
- containerPort: 8877


- name: containername-businessservicesspringboot
image: mydocker.com/businessservicesspringboot:latest
resources:
limits:
memory: "800Mi"
cpu: "800m"
requests:
memory: "613Mi"
cpu: "400m"
ports:
- containerPort: 8855
kubectl apply  -f K8containers.yml
pod "mypodkindmetadataname" created

kubectl get pods
NAME READY STATUS RESTARTS AGE
mypodkindmetadataname 2/2 Running 0 11s

k8services.yml(如下)
apiVersion: v1
kind: Service
metadata:
name: myymlservice
labels:
name: myservicemetadatalabel
spec:
type: NodePort
ports:
- name: myrestservice-servicekind-port-name
port: 8857
targetPort: 8855
- name: myfrontend-servicekind-port-name
port: 8879
targetPort: 8877
selector:
name: mypodkindmetadataname

........
kubectl apply  -f K8services.yml
service "myymlservice" created

........
 minikube service myymlservice --url
http://192.168.99.100:30784
http://192.168.99.100:31751

........
 kubectl describe service myymlservice


Name: myymlservice
Namespace: default
Labels: name=myservicemetadatalabel
Annotations: kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"name":"myservicemetadatalabel"},"name":"myymlservice","namespace":"default"...
Selector: name=mypodkindmetadataname
Type: NodePort
IP: 10.107.75.205
Port: myrestservice-servicekind-port-name 8857/TCP
TargetPort: 8855/TCP
NodePort: myrestservice-servicekind-port-name 30784/TCP
Endpoints: <none>
Port: myfrontend-servicekind-port-name 8879/TCP
TargetPort: 8877/TCP
NodePort: myfrontend-servicekind-port-name 31751/TCP
Endpoints: <none>
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>

....

不幸的是,当我尝试调用“公开的”项目时,它仍然无法正常工作。

呼唤

http://192.168.99.100:30784/myrestmethod

不起作用

并打电话

http://192.168.99.100:31751

要么

http://192.168.99.100:31751/index.html

不起作用

有人看到我想念的东西。

APPEND(正在运行)

选择器在“名称”上不匹配,在标签上匹配。

k8containers.yml(部分在顶部)
apiVersion: v1
kind: Pod
metadata:
name: mypodkindmetadataname
labels:
myexamplelabelone: mylabelonevalue
myexamplelabeltwo: mylabeltwovalue

spec:

containers:

# Main application container
- name: containername-springbootfrontend
image: mydocker.com/webfrontendspringboot:latest
resources:
limits:
memory: "800Mi"
cpu: "800m"
requests:
memory: "612Mi"
cpu: "400m"
ports:
- containerPort: 8877


- name: containername-businessservicesspringboot
image: mydocker.com/businessservicesspringboot:latest
resources:
limits:
memory: "800Mi"
cpu: "800m"
requests:
memory: "613Mi"
cpu: "400m"
ports:
- containerPort: 8855

k8services.yml
apiVersion: v1
kind: Service
metadata:
name: myymlservice
labels:
name: myservicemetadatalabel
spec:
type: NodePort
ports:
- name: myrestservice-servicekind-port-name
port: 8857
targetPort: 8855
- name: myfrontend-servicekind-port-name
port: 8879
targetPort: 8877
selector:
myexamplelabelone: mylabelonevalue
myexamplelabeltwo: mylabeltwovalue

最佳答案

是的,您可以创建一个具有多个端口打开的单一服务,也可以创建指向容器端口的服务端口连接。

kind: Service
apiVersion: v1
metadata:
name: mymlservice
spec:
selector:
app: mymlapp
ports:
- name: servicename-1
port: 4444
targetPort: 8855
- name: servicename-2
port: 80
targetPort: 8877

目标端口要装到容器端口的位置。

关于docker - 具有多个容器的容器上具有多个裸露端口的单一服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55935077/

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