带有Keycloak Gatekeeper Sidecar的基础服务

问题描述

我正在尝试部署以下服务:

{{- if .Values.knativeDeploy }}
apiVersion: serving.knative.dev/v1
kind: Service
Metadata:
{{- if .Values.service.name }}
  name: {{ .Values.service.name }}
{{- else }}
  name: {{ template "fullname" . }}
{{- end }}
  labels:
    chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
spec:
  template:
    spec:
      containers:
      - image: quay.io/keycloak/keycloak-gatekeeper:9.0.3
        name: gatekeeper-sidecar
        ports:
        - containerPort: {{ .Values.keycloak.proxyPort }}
        env:
          - name: KEYCLOAK_CLIENT_SECRET
            valueFrom:
              secretKeyRef:
                name: {{ template "keycloakclient" . }}
                key: secret
        args:
        - --resources=uri=/*
        - --discovery-url={{ .Values.keycloak.url }}/auth/realms/{{ .Values.keycloak.realm }}
        - --client-id={{ template "keycloakclient" . }}
        - --client-secret=$(KEYCLOAK_CLIENT_SECRET)
        - --listen=0.0.0.0:{{ .Values.keycloak.proxyPort }} # listen on all interfaces
        - --enable-logging=true
        - --enable-json-logging=true
        - --upstream-url=http://127.0.0.1:{{ .Values.service.internalPort }} # To connect with the main container's port
        resources:
{{ toYaml .Values.gatekeeper.resources | indent 12 }}
      - name: {{ .Chart.Name }}
        image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
        imagePullPolicy: {{ .Values.image.pullPolicy }}
        env:
{{- range $pkey,$pval := .Values.env }}
        - name: {{ $pkey }}
          value: {{ quote $pval }}
{{- end }}
        envFrom:
{{ toYaml .Values.envFrom | indent 10 }}
        ports:
        - containerPort: {{ .Values.service.internalPort }}
        livenessProbe:
          httpGet:
            path: {{ .Values.probePath }}
            port: {{ .Values.service.internalPort }}
          initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }}
          periodSeconds: {{ .Values.livenessProbe.periodSeconds }}
          successthreshold: {{ .Values.livenessProbe.successthreshold }}
          timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }}
        readinessProbe:
          httpGet:
            path: {{ .Values.probePath }}
            port: {{ .Values.service.internalPort }}
          periodSeconds: {{ .Values.readinessProbe.periodSeconds }}
          successthreshold: {{ .Values.readinessProbe.successthreshold }}
          timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }}
        resources:
{{ toYaml .Values.resources | indent 12 }}
      terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }}
{{- end }}

哪个失败并出现以下错误

Error from server (BadRequest): error when creating "/tmp/helm-template-workdir-290082188/jx/output/namespaces/jx-staging/env/charts/docs/templates/part0-ksvc.yaml": admission webhook "webhook.serving.knative.dev" denied the request: mutation Failed: expected exactly one,got both: spec.template.spec.containers'

现在,如果我阅读规格(https://knative.dev/v0.15-docs/serving/getting-started-knative-app/),我可以看到以下示例:

apiVersion: serving.knative.dev/v1 # Current version of Knative
kind: Service
Metadata:
  name: helloworld-go # The name of the app
  namespace: default # The namespace the app will use
spec:
  template:
    spec:
      containers:
        - image: gcr.io/knative-samples/helloworld-go # The URL to the image of the app
          env:
            - name: TARGET # The environment variable printed out by the sample app
              value: "Go Sample v1"

具有完全相同的结构。现在,我的问题是:

  1. 如何在不等待部署的情况下验证山药? Intellij有一个k8n插件,但是我找不到计算机消耗的serve.knative.dev/v1的CRD模式。 (https://knative.dev/docs/serving/spec/knative-api-specification-1.0/
  2. knative是否允许有多个容器? (该配置可与apiVersion:apps / v1类型:部署完美配合使用)

解决方法

多容器是knative version 0.16中的alpha功能。 需要通过在multi-container ConfigMap中将enabled设置为config-features来启用此功能。因此,使用

编辑配置映射

kubectl edit cm config-features并启用该功能。

apiVersion: v1
kind: ConfigMap
metadata:
  name: config-features
  namespace: knative-serving
  labels:
    serving.knative.dev/release: devel
  annotations:
    knative.dev/example-checksum: "983ddf13"
data:
  _example: |
    ...
    # Indicates whether multi container support is enabled
    multi-container: "enabled"
    ...
,

您正在使用哪个版本的Knative?

对多个容器的支持为added as an alpha feature in 0.16。如果您未使用0.16或更高版本,或者未启用alpha标志,则该请求可能会被阻止。

在Knative中,有很多边缘情况需要定义多容器支持,因此默认设置是保守的,并且只允许使用一个容器,直到探索了约束为止。