Tick_charts deployment.yaml不适用于kubectl

时间:2019-11-22 12:19:35

标签: kubernetes yaml indentation kubectl

我正在尝试使用以下命令将deployment.yaml文件应用于我的Kubernetes集群:
kubectl apply -f .\deployment.yaml
但出现此错误:
error: error parsing .\deployment.yaml: error converting YAML to JSON: yaml: line 27: could not find expected ':'

yaml文件与github上的原始文件完全相同:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: {{ template "fullname" . }}
  labels:
    app: {{ template "fullname" . }}
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
    release: "{{ .Release.Name }}"
    heritage: "{{ .Release.Service }}"
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: {{ template "fullname" . }}
      annotations:
        # Include a hash of the config in the pod template
        # This means that if the config changes, the deployment will be rolled
        checksum/config: {{ include (print .Template.BasePath "/config.yaml") . | sha256sum }}
    spec:
      containers:
      - name: {{ template "fullname" . }}
        image: "{{ .Values.image.repo }}:{{ .Values.image.tag }}"
        imagePullPolicy: {{ .Values.image.pullPolicy | quote }}
        resources:
{{ toYaml .Values.resources | indent 10 }}
        ports:
        - name: api
          containerPort: {{ .Values.config.http.bind_address }}
        {{- if .Values.config.graphite.enabled }}
        - name: graphite
          containerPort: {{ .Values.config.graphite.bind_address }}
        {{- end }}
        {{- if .Values.config.collectd.enabled }}
        - name: collectd
          containerPort: {{ .Values.config.collectd.bind_address }}
        {{- end }}
        {{- if .Values.config.udp.enabled }}
        - name: udp
          containerPort: {{ .Values.config.udp.bind_address }}
        {{- end }}
        {{- if .Values.config.opentsdb.enabled }}
        - name: opentsdb
          containerPort: {{ .Values.config.opentsdb.bind_address }}
        {{- end }}
        livenessProbe:
          httpGet:
            path: /ping
            port: api
          initialDelaySeconds: 30
          timeoutSeconds: 5
        readinessProbe:
          httpGet:
            path: /ping
            port: api
          initialDelaySeconds: 5
          timeoutSeconds: 1
        volumeMounts:
        - name: data
          mountPath: {{ .Values.config.storage_directory }}
        - name: config
          mountPath: /etc/influxdb
      {{- if .Values.priorityClassName }}
      priorityClassName: {{ .Values.priorityClassName }}
      {{- end }}
    {{- with .Values.nodeSelector }}
      nodeSelector:
{{ toYaml . | indent 8 }}
    {{- end }}
    {{- with .Values.affinity }}
      affinity:
{{ toYaml . | indent 8 }}
    {{- end }}
    {{- with .Values.tolerations }}
      tolerations:
{{ toYaml . | indent 8 }}
    {{- end }}
      volumes:
      - name: data
      {{- if .Values.persistence.enabled }}
        persistentVolumeClaim:
          claimName: {{ template "fullname" . }}
      {{- else }}
        emptyDir: {}
      {{- end }}
      - name: config
        configMap:
          name: {{ template "fullname" . }}

因此,根据错误消息,第27行:

26 {{ toYaml .Values.resources | indent 10 }}
27         ports:
28         - name: api

缺少:,根据我所见它在那里。 为什么会出现此错误?

1 个答案:

答案 0 :(得分:1)

不确定为什么要尝试应用简单的helm's deployment.yaml(这是Values.yaml文件的框架)

为了正确安装它,建议您遵循最新的InfluxDB文档,并从稳定/ influxdb存储库中使用Helm进行安装。


安装头盔:

curl https://raw.githubusercontent.com/helm/helm/master/scripts/get | bash
kubectl create serviceaccount --namespace kube-system tiller
kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller
helm init --service-account tiller / helm init --service-account tiller --upgrade(in case you have already done heln init)
helm repo update

安装图表:

helm install --name my-release stable/influxdb

LAST DEPLOYED: Fri Nov 22 14:10:41 2019
NAMESPACE: default
STATUS: DEPLOYED

RESOURCES:
==> v1/ConfigMap
NAME                 DATA  AGE
my-release-influxdb  1     1s

==> v1/Pod(related)
NAME                   READY  STATUS   RESTARTS  AGE
my-release-influxdb-0  0/1    Pending  0         1s

==> v1/Service
NAME                 TYPE       CLUSTER-IP  EXTERNAL-IP  PORT(S)            AGE
my-release-influxdb  ClusterIP  *.*.*.*   <none>       8086/TCP,8088/TCP  1s

==> v1/StatefulSet
NAME                 READY  AGE
my-release-influxdb  0/1    1s


NOTES:
InfluxDB can be accessed via port 8086 on the following DNS name from within your cluster:

- http://my-release-influxdb.default:8086

You can easily connect to the remote instance with your local influx cli. To forward the API port to localhost:8086 run the following:

- kubectl port-forward --namespace default $(kubectl get pods --namespace default -l app=my-release-influxdb -o jsonpath='{ .items[0].metadata.name }') 8086:8086

You can also connect to the influx cli from inside the container. To open a shell session in the InfluxDB pod run the following:

- kubectl exec -i -t --namespace default $(kubectl get pods --namespace default -l app=my-release-influxdb -o jsonpath='{.items[0].metadata.name}') /bin/sh

To tail the logs for the InfluxDB pod run the following:

- kubectl logs -f --namespace default $(kubectl get pods --namespace default -l app=my-release-influxdb -o jsonpath='{ .items[0].metadata.name }')



kubectl get all -l app=my-release-influxdb
NAME                        READY   STATUS    RESTARTS   AGE
pod/my-release-influxdb-0   1/1     Running   0          11m

NAME                          TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)             AGE
service/my-release-influxdb   ClusterIP   CLUSTER-IP  EXTERNAL-IP  PORT(S)            AGE
my-release-influxdb  ClusterIP  *.*.*.*    <none>        8086/TCP,8088/TCP   11m

NAME                                   READY   AGE
statefulset.apps/my-release-influxdb   1/1     11m