首页 > 解决方案 > 解析模板/deployment.yaml 时出错:json:第 1 行:无效字符“{”正在寻找对象键字符串的开头

问题描述

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

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

解析模板/deployment.yaml 时出错:json:第 1 行:无效字符“{”正在寻找对象键字符串的开头

有人遇到过这个问题吗?

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

  {{- 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 }}

任何线索将不胜感激!

问候玛尼

标签: kuberneteskubernetes-helmkubernetes-ingresskubernetes-podnexus3

解决方案


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

更多关于使用 helm 的信息在这里

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

希望这可以帮助。


推荐阅读