kubernetes 舵面图允许多服务吗?

sf6xfgos  于 2023-08-03  发布在  Kubernetes
关注(0)|答案(2)|浏览(82)

我是Helm的新手,想知道,如果它被允许在service.yaml文件中有多个服务:

apiVersion: v1
kind: Service
metadata:
  name: {{ include "keycloak.fullname" . }}
  labels:
    {{- include "keycloak.labels" . | nindent 4 }}
spec:
  type: {{ .Values.service.type }}
  ports:
    - port: {{ .Values.service.port }}
      targetPort: http
      protocol: TCP
      name: http
  selector:
    {{- include "keycloak.selectorLabels" . | nindent 4 }}

---

apiVersion: v1
kind: Service
metadata:
  name: {{ include "keycloak.fullname" . }}
  labels:
    {{- include "keycloak.labels" . | nindent 4 }}
spec:
  type: {{ .Values.service.type }}
  ports:
    - port: {{ .Values.service.port }}
      targetPort: http
      protocol: TCP
      name: http
  selector:
    {{- include "keycloak.selectorLabels" . | nindent 4 }}

字符串

omvjsjqw

omvjsjqw1#

是的,你有什么问题吗?
一种更简洁的方法是使用两个不同的文件service-a.yaml和service-b.yaml
注意:最好不要让两个服务具有相同的名称。

emeijp43

emeijp432#

您可以使用List类型在一个文件中定义多个服务

apiVersion: v1
items:
- apiVersion: v1
  kind: Service
  metadata:
    name: {{ .Values.appName }}{{ .Values.nameSuffix }}
    namespace: {{ .Values.projectNamespace }}
    labels:
      app: {{ .Values.appName }}
      owner: {{ .Values.ownerName }}
      project: {{ .Values.projectName }}
  spec:
    ports:
      - name: 8082-tcp
        port: 8082
        protocol: TCP
        targetPort: 8082
    selector:
      deploymentconfig: {{ .Values.appName }}{{ .Values.nameSuffix }}
    sessionAffinity: None
    type: ClusterIP
  status:
    loadBalancer: {}
- apiVersion: v1
  kind: Service
  metadata:
    name: {{ .Values.appName }}
    namespace: {{ .Values.projectNamespace }}
    labels:
      app: {{ .Values.appName }}
      owner: {{ .Values.ownerName }}
      project: {{ .Values.projectName }}
  spec:
    ports:
      - name: 8082-tcp
        port: 8082
        protocol: TCP
        targetPort: 8082
    selector:
      deploymentconfig: {{ .Values.appName }}{{ .Values.nameSuffix }}
    sessionAffinity: None
    type: ClusterIP
  status:
    loadBalancer: {}
kind: List
metadata:
  resourceVersion: ""
  selfLink: ""

字符串

相关问题