<p>I'm using kbuernetes version 1.20.5 with docker 19.03.8 on a virtual machine. I'm trying to create a test elk cluster with kubernetes. When i enter kubectl create i get the followig error:</p>
<pre><code>error parsing testserver.yaml: error converting YAML to JSON: yaml: line 17: could not find expected ':'
</code></pre>
<p>I keep checking but can't find where the missing &quot;:&quot; should be. I validated the yaml in yaml lint and i get valid yaml result. The yaml file is like this:</p>
<pre><code>#namespace define
apiVersion: v1
kind: Namespace
metadata:
  name: testlog

---
#esnodes
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: testnode1
  name: testnode1
  namespace: testlog
spec:
  replicas: 1
  selector:
    matchLabels:
      app: testnode1
  template:
    metadata:
      labels:
        app: testnode1
    spec:
      containers:
      - env:
        - name: ES_JAVA_OPTS
          value: -Xms768m -Xmx768m
        - name: MAX_LOCKED_MEMORY
          value: unlimited
        - name: bootstrap.memory_lock
          value: &quot;true&quot;
        - name: cluster.initial_master_nodes
          value: testnode1,testnode2,testnode3
        - name: cluster.name
          value: testcluster
        - name: discovery.seed_hosts
          value: testnode1,testnode2,testnode3
        - name: http.cors.allow-origin
          value: &quot;*&quot;
        - name: network.host
          value: 0.0.0.0
        - name: node.data
          value: &quot;false&quot;
        - name: node.name
          value: testnode1
        image: amazon/opendistro-for-elasticsearch:1.8.0
        name: testnode1
        securityContext:
          privileged: true
        volumeMounts:
        - mountPath: /usr/share/elasticsearch/data
          name: testnode1-claim0
#      restartPolicy: Always
      volumes:
        - name: testnode1-claim0
          hostPath:
            path: /logtest/es1
            type: DirectoryOrCreate

---
#es1 portservice
apiVersion: v1
kind: Service
metadata:
  name: testnode1-service
  namespace: testlog
  labels:
    app: testnode1
spec:
  type: NodePort
  ports:
  - port: 9200
    nodePort: 9201
    targetPort: 9200
    protocol: TCP
    name: testnode1-9200
  - port: 9300
    nodePort: 9301
    targetPort: 9300
    protocol: TCP
    name: testnode1-9300
  selector:
    app: testnode1


---
#es1 dns
apiVersion: v1
kind: Service
metadata:
  name: testnode1
  namespace: testlog
  labels:
    app: testnode1
spec:
  clusterIP: None
  selector:
    app: testnode1

---

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: testnode2
  name: testnode2
  namespace: testlog
spec:
  replicas: 1
  selector:
    matchLabels:
      app: testnode2
  template:
    metadata:
      labels:
        app: testnode2
    spec:
      containers:
      - env:
        - name: ES_JAVA_OPTS
          value: -Xms768m -Xmx768m
        - name: MAX_LOCKED_MEMORY
          value: unlimited
        - name: bootstrap.memory_lock
          value: &quot;true&quot;
        - name: cluster.initial_master_nodes
          value: testnode1,testnode2,testnode3
        - name: cluster.name
          value: testcluster
        - name: discovery.seed_hosts
          value: testnode1,testnode2,testnode3
        - name: http.cors.allow-origin
          value: &quot;*&quot;
        - name: network.host
          value: 0.0.0.0
        - name: node.data
          value: &quot;true&quot;
        - name: node.name
          value: testnode2
        image: amazon/opendistro-for-elasticsearch:1.8.0
        name: testnode2
        securityContext:
          privileged: true
        volumeMounts:
        - mountPath: /usr/share/elasticsearch/data
          name: testnode2-claim0
#      restartPolicy: Always
      volumes:
        - name: testnode2-claim0
          hostPath:
            path: /logtest/es2
            type: DirectoryOrCreate

---

#es1 dns
apiVersion: v1
kind: Service
metadata:
  name: testnode2
  namespace: testlog
  labels:
    app: testnode2
spec:
  clusterIP: None
  selector:
    app: testnode2

----

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: testnode3
  name: testnode3
  namespace: testlog
spec:
  replicas: 1
  selector:
    matchLabels:
      app: testnode3
  template:
    metadata:
      labels:
        app: testnode3
    spec:
      containers:
      - env:
        - name: ES_JAVA_OPTS
          value: -Xms768m -Xmx768m
        - name: MAX_LOCKED_MEMORY
          value: unlimited
        - name: bootstrap.memory_lock
          value: &quot;true&quot;
        - name: cluster.initial_master_nodes
          value: testnode1,testnode2,testnode3
        - name: cluster.name
          value: testcluster
        - name: discovery.seed_hosts
          value: testnode1,testnode2,testnode3
        - name: http.cors.allow-origin
          value: &quot;*&quot;
        - name: network.host
          value: 0.0.0.0
        - name: node.data
          value: &quot;true&quot;
        - name: node.name
          value: testnode3
        image: amazon/opendistro-for-elasticsearch:1.8.0
        name: testnode3
        securityContext:
          privileged: true
        volumeMounts:
        - mountPath: /usr/share/elasticsearch/data
          name: testnode3-claim0
#      restartPolicy: Always
      volumes:
        - name: testnode3-claim0
          hostPath:
            path: /logtest/es3
            type: DirectoryOrCreate

---

#es3 dns
apiVersion: v1
kind: Service
metadata:
  name: testnode3
  namespace: testlog
  labels:
    app: testnode3
spec:
  clusterIP: None
  selector:
    app: testnode3

---

#kibana dep
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: kibana
  name: kibana
  namespace: testlog
spec:
  replicas: 1
  selector:
    matchLabels:
      app: kibana
  template:
    metadata:
      labels:
        app: kibana
    spec:
      containers:
      - env:
        - name: ELASTICSEARCH_HOSTS
          value: http://testnode1:9200
        - name: ELASTICSEARCH_URL
          value: http://testnode1:9200
        image: amazon/opendistro-for-elasticsearch-kibana:1.8.0
        name: kibana
#      restartPolicy: Always

---
#kibana  dns
apiVersion: v1
kind: Service
metadata:
  name: kibana
  namespace: testlog
  labels:
    app: kibana
spec:
  clusterIP: None
  selector:
    app: kibana
---
#kibana port servi
apiVersion: v1
kind: Service
metadata:
  name: kibana-service
  namespace: testlog
  labels:
    app: kibana
spec:
  type: NodePort
  ports:
  - port: 5601
    nodePort: 5602
    targetPort: 5601
    protocol: TCP
    name: kibana
  selector:
    app: kibana

----

#elasticsearch-hq deployment
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: elasticsearch-hq
  name: elasticsearch-hq
  namespace: testlog
spec:
  replicas: 1
  selector:
    matchLabels:
      app: elasticsearch-hq
  template:
    metadata:
      labels:
        app: elasticsearch-hq
    spec:
      containers:
      - image: elastichq/elasticsearch-hq
        name: elasticsearch-hq
#      restartPolicy: Always

---
#elasticsearch-hq port service
apiVersion: v1
kind: Service
metadata:
  name: elasticsearch-hq-service
  namespace: testlog
  labels:
    app: elasticsearch-hq
spec:
  type: NodePort
  ports:
  - port: 8081
    nodePort: 8081
    targetPort: 5000
    protocol: TCP
    name: elasticsearch-hq
  selector:
    app: elasticsearch-hq
</code></pre>

Nyquillus
<p>There are couple of issues in the <code>yaml</code> file:</p>
<ol>
<li><p>You have used four <code>-</code> in some places whereas the separator is three <code>-</code>.</p>
</li>
<li><p>Once, you fix the first issue, you'll see the following errors related to <code>NodePort</code> services as the valid range for the <code>nodePort</code> is <code>30000-32767</code>:</p>
</li>
</ol>
<pre><code>Error from server (Invalid): error when creating &quot;testserver.yaml&quot;: Service &quot;testnode1-service&quot; is invalid: spec.ports[0].nodePort: Invalid value: 9201: provided port is not in the valid range. The range of valid ports is 30000-32767
Error from server (Invalid): error when creating &quot;testserver.yaml&quot;: Service &quot;kibana-service&quot; is invalid: spec.ports[0].nodePort: Invalid value: 5602: provided port is not in the valid range. The range of valid ports is 30000-32767
Error from server (Invalid): error when creating &quot;testserver.yaml&quot;: Service &quot;elasticsearch-hq-service&quot; is invalid: spec.ports[0].nodePort: Invalid value: 8081: provided port is not in the valid range. The range of valid ports is 30000-32767
</code></pre>
<p>Fixing both the errors will resolve the <code>yaml</code> issues.</p>
<p>Below is the full working <code>yaml</code> file:</p>
<pre><code>#namespace define
apiVersion: v1
kind: Namespace
metadata:
  name: testlog

---
#esnodes
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: testnode1
  name: testnode1
  namespace: testlog
spec:
  replicas: 1
  selector:
    matchLabels:
      app: testnode1
  template:
    metadata:
      labels:
        app: testnode1
    spec:
      containers:
      - env:
        - name: ES_JAVA_OPTS
          value: -Xms768m -Xmx768m
        - name: MAX_LOCKED_MEMORY
          value: unlimited
        - name: bootstrap.memory_lock
          value: &quot;true&quot;
        - name: cluster.initial_master_nodes
          value: testnode1,testnode2,testnode3
        - name: cluster.name
          value: testcluster
        - name: discovery.seed_hosts
          value: testnode1,testnode2,testnode3
        - name: http.cors.allow-origin
          value: &quot;*&quot;
        - name: network.host
          value: 0.0.0.0
        - name: node.data
          value: &quot;false&quot;
        - name: node.name
          value: testnode1
        image: amazon/opendistro-for-elasticsearch:1.8.0
        name: testnode1
        securityContext:
          privileged: true
        volumeMounts:
        - mountPath: /usr/share/elasticsearch/data
          name: testnode1-claim0
#      restartPolicy: Always
      volumes:
        - name: testnode1-claim0
          hostPath:
            path: /logtest/es1
            type: DirectoryOrCreate


---
#es1 portservice
apiVersion: v1
kind: Service
metadata:
  name: testnode1-service
  namespace: testlog
  labels:
    app: testnode1
spec:
  type: NodePort
  ports:
  - port: 9200
    nodePort: 31201
    targetPort: 9200
    protocol: TCP
    name: testnode1-9200
  - port: 9300
    nodePort: 31301
    targetPort: 9300
    protocol: TCP
    name: testnode1-9300
  selector:
    app: testnode1



---
#es1 dns
apiVersion: v1
kind: Service
metadata:
  name: testnode1
  namespace: testlog
  labels:
    app: testnode1
spec:
  clusterIP: None
  selector:
    app: testnode1

---

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: testnode2
  name: testnode2
  namespace: testlog
spec:
  replicas: 1
  selector:
    matchLabels:
      app: testnode2
  template:
    metadata:
      labels:
        app: testnode2
    spec:
      containers:
      - env:
        - name: ES_JAVA_OPTS
          value: -Xms768m -Xmx768m
        - name: MAX_LOCKED_MEMORY
          value: unlimited
        - name: bootstrap.memory_lock
          value: &quot;true&quot;
        - name: cluster.initial_master_nodes
          value: testnode1,testnode2,testnode3
        - name: cluster.name
          value: testcluster
        - name: discovery.seed_hosts
          value: testnode1,testnode2,testnode3
        - name: http.cors.allow-origin
          value: &quot;*&quot;
        - name: network.host
          value: 0.0.0.0
        - name: node.data
          value: &quot;true&quot;
        - name: node.name
          value: testnode2
        image: amazon/opendistro-for-elasticsearch:1.8.0
        name: testnode2
        securityContext:
          privileged: true
        volumeMounts:
        - mountPath: /usr/share/elasticsearch/data
          name: testnode2-claim0
#      restartPolicy: Always
      volumes:
        - name: testnode2-claim0
          hostPath:
            path: /logtest/es2
            type: DirectoryOrCreate

---

#es1 dns
apiVersion: v1
kind: Service
metadata:
  name: testnode2
  namespace: testlog
  labels:
    app: testnode2
spec:
  clusterIP: None
  selector:
    app: testnode2

---

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: testnode3
  name: testnode3
  namespace: testlog
spec:
  replicas: 1
  selector:
    matchLabels:
      app: testnode3
  template:
    metadata:
      labels:
        app: testnode3
    spec:
      containers:
      - env:
        - name: ES_JAVA_OPTS
          value: -Xms768m -Xmx768m
        - name: MAX_LOCKED_MEMORY
          value: unlimited
        - name: bootstrap.memory_lock
          value: &quot;true&quot;
        - name: cluster.initial_master_nodes
          value: testnode1,testnode2,testnode3
        - name: cluster.name
          value: testcluster
        - name: discovery.seed_hosts
          value: testnode1,testnode2,testnode3
        - name: http.cors.allow-origin
          value: &quot;*&quot;
        - name: network.host
          value: 0.0.0.0
        - name: node.data
          value: &quot;true&quot;
        - name: node.name
          value: testnode3
        image: amazon/opendistro-for-elasticsearch:1.8.0
        name: testnode3
        securityContext:
          privileged: true
        volumeMounts:
        - mountPath: /usr/share/elasticsearch/data
          name: testnode3-claim0
#      restartPolicy: Always
      volumes:
        - name: testnode3-claim0
          hostPath:
            path: /logtest/es3
            type: DirectoryOrCreate

---
#es3 dns
apiVersion: v1
kind: Service
metadata:
  name: testnode3
  namespace: testlog
  labels:
    app: testnode3
spec:
  clusterIP: None
  selector:
    app: testnode3

---

#kibana dep
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: kibana
  name: kibana
  namespace: testlog
spec:
  replicas: 1
  selector:
    matchLabels:
      app: kibana
  template:
    metadata:
        app: kibana
    spec:
      containers:
      - env:
        - name: ELASTICSEARCH_HOSTS
          value: http://testnode1:9200
        - name: ELASTICSEARCH_URL
          value: http://testnode1:9200
        image: amazon/opendistro-for-elasticsearch-kibana:1.8.0
        name: kibana
#      restartPolicy: Always

---
#kibana  dns
apiVersion: v1
kind: Service
metadata:
  name: kibana
  namespace: testlog
  labels:
    app: kibana
spec:
  clusterIP: None
  selector:
    app: kibana
---
#kibana port servi
apiVersion: v1
kind: Service
metadata:
  name: kibana-service
  namespace: testlog
  labels:
    app: kibana
spec:
  type: NodePort
  ports:
  - port: 5601
    nodePort: 31602
    targetPort: 5601
    protocol: TCP
    name: kibana
  selector:
    app: kibana

---
#elasticsearch-hq deployment
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: elasticsearch-hq
  name: elasticsearch-hq
  namespace: testlog
spec:
  replicas: 1
  selector:
    matchLabels:
      app: elasticsearch-hq
  template:
    metadata:
      labels:
        app: elasticsearch-hq
    spec:
      containers:
      - image: elastichq/elasticsearch-hq
        name: elasticsearch-hq
#      restartPolicy: Always

---
#elasticsearch-hq port service
apiVersion: v1
kind: Service
metadata:
  name: elasticsearch-hq-service
  namespace: testlog
  labels:
    app: elasticsearch-hq
spec:
  type: NodePort
  ports:
  - port: 8081
    nodePort: 31081
    targetPort: 5000
    protocol: TCP
    name: elasticsearch-hq
  selector:
    app: elasticsearch-hq
</code></pre>
