Welcome to the Linux Foundation Forum!

simpleapp.yaml from labs 3 & 5

cfree
cfree Posts: 2
edited July 2018 in LFD259 Class Forum
I'm taking the course and I tried both copying/pasting and manually typing out the yaml changes for simpleapp.yaml in labs 3 and 5. 


It breaks and can't parse what I entered in from the PDF. I get:


 


"craigf@controller-0:~$ kubectl create -f app1/simpleapp2.yaml


error: error parsing app1/simpleapp.yaml: error converting YAML to JSON: yaml: line 41: did not find expected key"


 


I'm unable to continue the labs because I can't get past these steps. I skipped the end of the 3rd lab and now I'm stuck on the 5th lab. I'm not really familiar with Kubernetes *or* yaml files, so I'm not sure what to look for. Can you provide working yaml files for all the lab steps or at least point me to a repo so I can compare what I have? Git tags at each of the lab steps would be amazing.

Comments

  • chrispokorni
    chrispokorni Posts: 2,305

    Hi,

    I think that learning to create and troubleshoot yaml files is a major part of learning Kubernetes.

    Most yaml files needed to complete the labs are part of the downloadable examples package.

    However, simpleapp.yaml is not, because it is a file that is created by each student in lab 3.1, then re-used later in other labs. 

    To help with yaml file whitespacing and field alignment troubleshooting, you can use 


    kubectl explain deployment --recursive

    It will produce an output of all the possible fields in a deployment yaml file. You can compare it with your simpleapp.yaml and hopefully be able to troubleshoot the whitespacing or the fields alignment in it. 

    A good source of sample yaml files is kubernetes.io.

    Before pasting yaml content from pdf to vim, paste it into a simple text editor (I use gedit) and fix the whitespacing and only then paste it into vim. Will save you some time and headache. 

    Regards, 

    -Chris

  • cfree
    cfree Posts: 2
    edited August 2018

    As I mentioned, I copy/pasted from the PDF as well as manually typed in the changes to the yaml file, which suggests to me that the PDF is incorrect. The other forum entries suggest that I'm not the only one with this issue. Yaml file attachment? Git diff? Maybe a gist? Something?

  • chrispokorni
    chrispokorni Posts: 2,305
    edited August 2018

    Hi, 

    Most issues with yaml files are whitespace related. Considering that the first created simpleapp.yaml file is correct, deleting a few lines would not alter the whitespacing of the file. Paying attention to whitespacing will be important when adding blocks of code to the yaml file - but only the whitespacing of the new block, not the already existing yaml code.

    Kubernetes yaml files have a similar structure, regardless of the defined resource. Take a look thru the course and the official documentation to discover the structure similarities in order to understand the whitespacing and indentation rules. Also, do not use tab for indentation, use the space bar - two spaces for each indentation.

    When I completed these labs I did not find any git repo that supported them. However, I did spend some time researching yaml in particular, to understand its overall structure and usage, even outside of Kubernetes.

    Where you able to try the "kubectl explain" command? Did it provide any help?

    Regards, 

    -Chris

  • serewicz
    serewicz Posts: 1,000
    edited August 2018

    Hello,

    A copy and paste from a PDF can sometimes lead to issues, but these are often with the way single quotes are transfered. They become a back-quote.  Other characters can be inserted which can cause issues. YAML is sensitive and requires only whitespace.  

    The first thing to try is to run cat -vet <file>.yaml  This will show non-printable characters which may be causing an issue. 

    There is a tarball of yaml files which you can download via a wget mentioned in lab 3 overview section. Using find ~ -name <file>.yaml you can find the particular YAML file and either copy to the home directory or use the diff command to determine what is different from that file to yours.

    The third option is to use is https://www.json2yaml.com/ which allows you to paste and edit the YAML while seeing the JSON be generated as you type. This can be useful to find the proper number of spaces if it is unclear.

    Regards,

     

Categories

Upcoming Training