错误解析 templates/deployment.yaml:json:第 1 行:无效字符“{”寻找对象键字符串的开头

error parsing templates/deployment.yaml: json: line 1: invalid character '{' looking for beginning of object key string

当我尝试使用 kubernetes 部署 nexus 时出现以下错误。

命令: kubectl appy -f templates/deployment.yaml

error parsing templates/deployment.yaml: json: line 1: invalid character '{' looking for beginning of object key string

有人遇到过这个问题吗?

请找到我正在尝试的以下代码:

  {{- if .Values.localSetup.enabled }}
  apiVersion: apps/v1
  kind: Deployment
    {{- else }}
  apiVersion: apps/v1
  kind: StatefulSet
    {{- end }}
  metadata:
    labels:
      app: nexus
    name: nexus
  spec:
    replicas: 1
    selector:
      matchLabels:
        app: nexus
    template:
      metadata:
        labels:
          app: nexus
      spec:
    {{- if .Values.localSetup.enabled }}
  volumes:
    - name: nexus-data
      persistentVolumeClaim:
        claimName: nexus-pv-claim
    - name: nexus-data-backup
      persistentVolumeClaim:
        claimName: nexus-backup-pv-claim
    {{- end }}
  containers:
    - name: nexus
      image: "quay.io/travelaudience/docker-nexus:3.15.2"
      imagePullPolicy: Always
      env:
        - name: INSTALL4J_ADD_VM_PARAMS
          value: "-Xms1200M -Xmx1200M -XX:MaxDirectMemorySize=2G -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap"
      resources:
        requests:
          cpu: 250m
          memory: 4800Mi
      ports:
        - containerPort: {{ .Values.nexus.dockerPort }}
          name: nexus-docker-g
        - containerPort: {{ .Values.nexus.nexusPort }}
          name: nexus-http
      volumeMounts:
        - mountPath: "/nexus-data"
          name: nexus-data
        - mountPath: "/nexus-data/backup"
          name: nexus-data-backup
    {{- if .Values.useProbes.enabled }}
  livenessProbe:
    httpGet:
      path: {{ .Values.nexus.livenessProbe.path }}
      port: {{ .Values.nexus.nexusPort }}
    initialDelaySeconds: {{ .Values.nexus.livenessProbe.initialDelaySeconds }}
    periodSeconds: {{ .Values.nexus.livenessProbe.periodSeconds }}
    failureThreshold: {{ .Values.nexus.livenessProbe.failureThreshold }}
    {{- if .Values.nexus.livenessProbe.timeoutSeconds }}
  timeoutSeconds: {{ .Values.nexus.livenessProbe.timeoutSeconds }}
    {{- end }}
  readinessProbe:
    httpGet:
      path: {{ .Values.nexus.readinessProbe.path }}
      port: {{ .Values.nexus.nexusPort }}
    initialDelaySeconds: {{ .Values.nexus.readinessProbe.initialDelaySeconds }}
    periodSeconds: {{ .Values.nexus.readinessProbe.periodSeconds }}
    failureThreshold: {{ .Values.nexus.readinessProbe.failureThreshold }}
    {{- if .Values.nexus.readinessProbe.timeoutSeconds }}
  timeoutSeconds: {{ .Values.nexus.readinessProbe.timeoutSeconds }}
    {{- end }}
    {{- end }}

    {{- if .Values.nexusProxy.enabled }}
                    - name: nexus-proxy
                      image: "quay.io/travelaudience/docker-nexus-proxy:2.4.0_8u191"
                      imagePullPolicy: Always
                      env:
                        - name: ALLOWED_USER_AGENTS_ON_ROOT_REGEX
                          value: "GoogleHC"
                        - name: CLOUD_IAM_AUTH_ENABLED
                          value: "false"
                        - name: BIND_PORT
                          value: {{ .Values.nexusProxy.targetPort | quote }}
                        - name: ENFORCE_HTTPS
                          value: "false"
                      {{- if .Values.localSetup.enabled }}
                    - name: NEXUS_DOCKER_HOST
                      value: {{ .Values.nexusProxy.nexusLocalDockerhost }}
                    - name: NEXUS_HTTP_HOST
                      value: {{ .Values.nexusProxy.nexusLocalHttphost }}
                      {{- else }}
                    - name: NEXUS_DOCKER_HOST
                      value: {{ .Values.nexusProxy.nexusDockerHost}}
                    - name: NEXUS_HTTP_HOST
                      value: {{ .Values.nexusProxy.nexusHttpHost }}
                      {{- end }}
                    - name: UPSTREAM_DOCKER_PORT
                      value: {{ .Values.nexus.dockerPort | quote }}
                    - name: UPSTREAM_HTTP_PORT
                      value: {{ .Values.nexus.nexusPort | quote }}
                    - name: UPSTREAM_HOST
                      value: "localhost"
  ports:
    - containerPort: {{ .Values.nexusProxy.targetPort }}
      name: proxy-port
    {{- end }}
    {{- if .Values.nexusBackup.enabled }}
    - name: nexus-backup
      image: "quay.io/travelaudience/docker-nexus-backup:1.4.0"
      imagePullPolicy: Always
      env:
        - name: NEXUS_AUTHORIZATION
          value: false
        - name: NEXUS_BACKUP_DIRECTORY
          value: /nexus-data/backup
        - name: NEXUS_DATA_DIRECTORY
          value: /nexus-data
        - name: NEXUS_LOCAL_HOST_PORT
          value: "localhost:8081"
        - name: OFFLINE_REPOS
          value: "maven-central maven-public maven-releases maven-snapshots"
        - name: TARGET_BUCKET
          value: "gs://nexus-backup"
        - name: GRACE_PERIOD
          value: "60"
        - name: TRIGGER_FILE
          value: .backup
      volumeMounts:
        - mountPath: /nexus-data
          name: nexus-data
        - mountPath: /nexus-data/backup
          name: nexus-data-backup
  terminationGracePeriodSeconds: 10

    {{- end }}

    {{- if .Values.persistence.enabled }}
  volumeClaimTemplates:
    - metadata:
        name: nexus-data
      spec:
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 32Gi
        storageClassName: {{ .Values.persistence.storageClass }}
    - metadata:
        name: nexus-data-backup
      spec:
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 32Gi
        storageClassName: {{ .Values.persistence.storageClass }}
    {{- end }}

如有任何线索,我们将不胜感激!

问候 马尼

您在此处提供的模板是helm chart的一部分,可以使用helm-cli而不是kubectl apply进行部署。

有关使用 helm 的更多信息是 here

您还可以在 this 官方稳定 helm 图表中获取使用 helm 安装 nexus 的说明。

希望对您有所帮助。