gpt4 book ai didi

kubernetes - 服务选择器与部署选择器匹配标签

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

我知道服务使用选择器来确定哪些 Pod 通过它们的标签将流量路由到。

apiVersion: v1
kind: Service
metadata:
name: svc
spec:
ports:
- name: tcp
protocol: TCP
port: 443
targetPort: 443
selector:
app: nginx
这一切都很好。
现在这个选择器和 spec.selector 的选择器有什么区别?从部署。我知道使用它是为了使部署可以匹配和管理其 pod。
但是我不明白为什么我需要额外的 matchLabels声明,不能像在服务中那样做。这在语义上有什么用?
apiVersion: apps/v1 
kind: Deployment
metadata:
name: nginx
spec:
selector:
matchLabels:
app: nginx
replicas: 1
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
提前致谢

最佳答案

就这么简单 - 在服务中 spec.selector您可以仅通过标签来识别要将流量路由到哪些 pod。
另一方面,在 Deployment spec.selector您有两个选项来决定将 pod 安排在哪个节点上,它们是:matchExpressions , matchLabels .
如果它回答了您的问题,请告诉我:)

关于kubernetes - 服务选择器与部署选择器匹配标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63875585/

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