Welcome to the Linux Foundation Forum!

Yaml file issue in CKAD lab 3.3

myousufm
myousufm Posts: 12
edited October 2021 in LFD259 Class Forum

Hello All,

Can anyone let me know if someone reached past the Lab Exercise 3.3. I am having having an issue with the YAML file. I have created file similar to what is mentioned in the course but while while using kubectl create -f myapp.yaml it gives below error

"error: error parsing myapp.yaml: error converting YAML to JSON: yaml: line 44: did not find expected key.

This may be very well a small thing to get sorted out but excuse my little experience with kubernetes as i am totally new to kubernetes. Any help would be much appreciate.

Thank You,

Answers

  • serewicz
    serewicz Posts: 1,000

    Hello,

    When you say you created something similar, perhaps you have a white space issue, or other typo. In this particular case I am not aware of using a myapp.yaml file in Exercise 3.3. I assume you are trying to reproduce the simpleapp.yaml. Did you diff the two files to see how they are different?

    Perhaps use a YAML checker to see where the whitespace issue may be. You can use this site json2yaml.com/ and edit the YAML to see what happens.

    Regards,

  • Hi Serewicz,

    Yes that's simpleapp I am referring to. I just had changed the name of the app and did check in https://codebeautify.org/yaml-validator showed me some whitespace, even after changing it i was not able to get that app working. I will check in json2yaml.com now and see.

  • I did check the same code in json2yaml.com and It gave me below error "x Did not find expected key while parsing a block mapping at line 27 column 5". I had never touched line 27

  • I checked in Microsoft vs code it gives me below errors only for one line and which is
    - name: goproxy

    the errors are

    {
    "resource": "/D:/studies/ckad/yousufapp.yaml",
    "owner": "generated_diagnostic_collection_name#2",
    "severity": 8,
    "message": "A block sequence may not be used as an implicit map key",
    "source": "YAML",
    "startLineNumber": 45,
    "startColumn": 1,
    "endLineNumber": 45,
    "endColumn": 21
    }

    {
    "resource": "/D:/studies/ckad/yousufapp.yaml",
    "owner": "generated_diagnostic_collection_name#2",
    "severity": 8,
    "message": "Implicit keys need to be on a single line",
    "source": "YAML",
    "startLineNumber": 45,
    "startColumn": 5,
    "endLineNumber": 45,
    "endColumn": 21
    }

    {
    "resource": "/D:/studies/ckad/yousufapp.yaml",
    "owner": "generated_diagnostic_collection_name#2",
    "severity": 8,
    "message": "Implicit map keys need to be followed by map values",
    "source": "YAML",
    "startLineNumber": 45,
    "startColumn": 5,
    "endLineNumber": 45,
    "endColumn": 21
    }

  • chrispokorni
    chrispokorni Posts: 2,349

    Hi @myousufm,

    The YAML files for the simpleapp deployment provided in the SOLUTIONS tarball can be used as templates for other application deployments. Both containers defined follow the same indentation rules, with identical properties equally indented: name: simpleapp and name: goproxy start at column 9. With reference to the name fields, other fields will be indented to the right +2, +4, or more spaces, or to the left -2, -4, or more spaces.

    Regards,
    -Chris

  • Hi @chrispokorni ,

    Thanks for your help here. I didnt get by +2, +4 and -2, -4 spaces. Sorry but I am new to yaml and didnt quiet get that. I have pasted below the code which i have that will give more clear pic of what may have gone wrong in the code. I am sure it would something small which i fail to understand at the moment.

    apiVersion: apps/v1
    kind: Deployment
    metadata:
    annotations:
    deployment.kubernetes.io/revision: "1"
    creationTimestamp: "2021-10-19T07:46:03Z"
    generation: 2
    labels:
    app: try1
    name: try1
    namespace: default
    resourceVersion: "7961"
    uid: c23f5399-e3b1-449a-be9e-ffd546905ab7
    spec:
    progressDeadlineSeconds: 600
    replicas: 6
    revisionHistoryLimit: 10
    selector:
    matchLabels:
    app: try1
    strategy:
    rollingUpdate:
    maxSurge: 25%
    maxUnavailable: 25%
    type: RollingUpdate
    template:
    metadata:
    creationTimestamp: null
    labels:
    app: try1
    spec:
    containers:
    - image: 10.103.26.66:5000/yousufapp
    imagePullPolicy: Always
    name: yousufapp
    readinessProbe:
    periodSeconds: 5
    exec:
    command:
    - cat
    - /tmp/healthy
    resources: {}
    terminationMessagePath: /dev/termination-log
    terminationMessagePolicy: File
    - name: goproxy
    image: k8s.gcr.io/goproxy:0.1
    ports:
    - containerPort: 8080
    readinessProbe:
    tcpSocket:
    port: 8080
    initialDelaySeconds: 5
    periodSeconds: 10
    livenessProbe:
    tcpSocket:
    port: 8080
    initialDelaySeconds: 15
    periodSeconds: 20
    dnsPolicy: ClusterFirst
    restartPolicy: Always
    schedulerName: default-scheduler
    securityContext: {}
    terminationGracePeriodSeconds: 30
    status:
    availableReplicas: 6
    conditions:
    - lastTransitionTime: "2021-10-19T07:46:39Z"
    lastUpdateTime: "2021-10-19T07:46:39Z"
    message: Deployment has minimum availability.
    reason: MinimumReplicasAvailable
    status: "True"
    type: Available
    - lastTransitionTime: "2021-10-19T07:46:03Z"
    lastUpdateTime: "2021-10-19T07:46:39Z"
    message: ReplicaSet "try1-66cb6c68c5" has successfully progressed.
    reason: NewReplicaSetAvailable
    status: "True"
    type: Progressing
    observedGeneration: 2
    readyReplicas: 6
    replicas: 6
    updatedReplicas: 6

  • chrispokorni
    chrispokorni Posts: 2,349

    Hi @myousufm,

    Please use the Code formatting tags when pasting YAML to preserve your code's indentation.

    Regards,
    -Chris

  • apiVersion: apps/v1 kind: Deployment metadata: annotations: deployment.kubernetes.io/revision: "1" creationTimestamp: "2021-10-19T07:46:03Z" generation: 2 labels: app: try1 name: try1 namespace: default resourceVersion: "7961" selfLink: /apis/apps/v1/namespaces/default/deployments/try1 uid: c23f5399-e3b1-449a-be9e-ffd546905ab7 spec: progressDeadlineSeconds: 600 replicas: 6 revisionHistoryLimit: 10 selector: matchLabels: app: try1 strategy: rollingUpdate: maxSurge: 25% maxUnavailable: 25% type: RollingUpdate template: metadata: creationTimestamp: null labels: app: try1 spec: containers: - image: 10.103.26.66:5000/yousufapp #<<-- EDIT for your registry IP imagePullPolicy: Always name: simpleapp readinessProbe: periodSeconds: 5 exec: command: - cat - /tmp/healthy resources: {} terminationMessagePath: /dev/termination-log terminationMessagePolicy: File - name: goproxy image: k8s.gcr.io/goproxy:0.1 ports: - containerPort: 8080 readinessProbe: tcpSocket: port: 8080 initialDelaySeconds: 5 periodSeconds: 10 livenessProbe: tcpSocket: port: 8080 initialDelaySeconds: 15 periodSeconds: 20 dnsPolicy: ClusterFirst restartPolicy: Always schedulerName: default-scheduler securityContext: {} terminationGracePeriodSeconds: 30 status: availableReplicas: 6 conditions: - lastTransitionTime: "2021-10-19T07:46:39Z" lastUpdateTime: "2021-10-19T07:46:39Z" message: Deployment has minimum availability. reason: MinimumReplicasAvailable status: "True" type: Available - lastTransitionTime: "2021-10-19T07:46:03Z" lastUpdateTime: "2021-10-19T07:46:39Z" message: ReplicaSet "try1-66cb6c68c5" has successfully progressed. reason: NewReplicaSetAvailable status: "True" type: Progressing observedGeneration: 2 readyReplicas: 6 replicas: 6 updatedReplicas: 6

  • This code worked, I did compare to the ones in the tarball of the labs and corrected a few indentations. But still have visual code giving me error on "creationTimestamp: null". not sure why that error but it works when i create using this file.

  • chrispokorni
    chrispokorni Posts: 2,349

    Hi @myousufm,

    I was hoping that the Code tags would format your YAML code as seen below, to help us troubleshoot your indentation:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      annotations:
        deployment.kubernetes.io/revision: "1"
      creationTimestamp: "2021-10-20T11:06:12Z"
      generation: 1
      labels:
        app: try1
      name: try1
      namespace: default
    ...
    

    Do you see any issues in 3.2.19 when running the deployment from the YAML file generated in step 3.2.18?

    Regards,
    -Chris

  • Hi Chris,

    I tried to add code tags but it didnt pasted as yours. Haven't got any issues in the previous steps in the lab its only on exercise 3.3 after adding the readiness probe and liveleness probe i got error. But worked a way around by checking the indentations in the simpleapp.yaml file provided in the tarball of the course material.

    Also if you have any suggestions on structure of the yaml file would help me in avoiding any further similar issues.

    Many thanks :)

  • myousufm
    myousufm Posts: 12
    edited October 2021

    Thanks

  • myousufm
    myousufm Posts: 12
    edited October 2021

    Thank You

Categories

Upcoming Training