r/openshift • • Apr 27 '24

Help needed! OpenShift YAML Nightmare

Hey folks,

Just aced the DO188 Podman exam, but now I'm in YAML hell with OpenShift. Seriously, does anyone even use this junk for real-world tasks?

I'm no YAML rookie thanks to Ansible, but OpenShift's YAML files are a maze of confusion. And now I'm expected to become a YAML guru overnight?

Is mastering this madness a prerequisite for DO280, or can I just stick to the oc
command and the GUI? Because spending hours wrangling YAML feels like a colossal waste of time.

Anyone got a shortcut or tough love advice to offer? Spare me the YAML evangelism, I need practical solutions.

Cheers,

0 Upvotes

13 comments sorted by

11

u/mostly_inefficient Apr 27 '24

Kubernetes fundamentally is about declarative configuration via manifests, so there isn't getting around that.

2

u/[deleted] Apr 27 '24

Got it but. Do you personally handle manifest creation from scratch, or do you rely on tools for editing existing manifests? Given my struggle with YAML complexity, what approach would you recommend for someone like me?

8

u/rimasb992 Apr 27 '24

I don't understand where you see the complexity because it's YAML. It's not because it's YAML. It's just a lot of details that go into manifest as they are driving the API calls.

I have worked a lot with Openshift, not once I have written a YAML manifest from scratch. You copy from existing and adapt what you need.

6

u/mostly_inefficient Apr 27 '24 edited Apr 27 '24

No, I administer a bunch of OpenShift 4 clusters and generally use manifest templates, modifying them as needed, etc. I don't think the skill to make a manifest from complete scratch is that useful

To add to this, I think the best thing is to try and deploy a few applications in your homelab, learn how they work and how to troubleshoot them, that is an excellent way to learn from trial and error.

6

u/SolarPoweredKeyboard Apr 27 '24

If you have an OpenShift console available, go into any resource you want to create and shift to yaml view to get an example.

Then you can navigate the yaml viewer and use shift-space or ctrl-space (can't remember which right now) to get suggestions on what keys are available to you for that resource.

Another way is to read the API specification for the resource, or check other examples in the OpenShift docs on the Red Hat site.

→ More replies (1)

14

u/triplewho Red Hat employee Apr 27 '24

What exactly are you having trouble with? You can use `oc explain` to help figure out specific things, but it depends on what exactly you're having issues with.

Example of using `oc explain` might be if you wanted to look up how to set the `nodeSelector` for a pod, you could do:

❯ oc explain pod.spec.nodeSelector
KIND:     Pod
VERSION:  v1

FIELD:    nodeSelector <map[string]string>

DESCRIPTION:
     NodeSelector is a selector which must be true for the pod to fit on a node.
     Selector which must match a node's labels for the pod to be scheduled on
     that node. More info:
     https://kubernetes.io/docs/concepts/configuration/assign-pod-node/

This tells us that it takes a map (dictionary) with the key and value both defined as strings. So, that's just a YAML dictionary like:

nodeSelector:
  "blah-key": "blah-value"

And I believe you have access to the docs during the exam. So as long as you had a general idea, you can probably find an example in the docs to help you.

The main thing I found confusing initially was how to define something like a Deployment. Because it has information about pods in it, but I can define pods on their own. So how do I know what to put in the Deployment yaml. But the easiest way to think of this is that anything that deploys a pod, will inherit the pod yaml attributes. So if we look at a deployment yaml example, when we get to the `.spec.template` section, everything there is the same as defining a pod:
https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#pod-template

So the only difference you need to think about is the deployment specific stuff. I mean, if the thing you need to do is create a deployment in the exam. But you're having trouble understanding where to put the number of replicas. Keep in mind that a pod doesn't define replicas, so we can rule out `.spec.template` as a large place to look for our answer. Back to `oc explain`, this time we know it's not specific to the pod, so we can check `deployment.spec`:

❯ oc explain deployment.spec
KIND:     Deployment
VERSION:  apps/v1

RESOURCE: spec <Object>

DESCRIPTION:
     Specification of the desired behavior of the Deployment.

     DeploymentSpec is the specification of the desired behavior of the
     Deployment.

FIELDS:
   minReadySeconds<integer>
     Minimum number of seconds for which a newly created pod should be ready
     without any of its container crashing, for it to be considered available.
     Defaults to 0 (pod will be considered available as soon as it is ready)

   paused<boolean>
     Indicates that the deployment is paused.

   progressDeadlineSeconds<integer>
     The maximum time in seconds for a deployment to make progress before it is
     considered to be failed. The deployment controller will continue to process
     failed deployments and a condition with a ProgressDeadlineExceeded reason
     will be surfaced in the deployment status. Note that progress will not be
     estimated during the time a deployment is paused. Defaults to 600s.

   replicas<integer>
     Number of desired pods. This is a pointer to distinguish between explicit
     zero and not specified. Defaults to 1.

   revisionHistoryLimit<integer>
     The number of old ReplicaSets to retain to allow rollback. This is a
     pointer to distinguish between explicit zero and not specified. Defaults to
     10.

   selector<Object> -required-
     Label selector for pods. Existing ReplicaSets whose pods are selected by
     this will be the ones affected by this deployment. It must match the pod
     template's labels.

   strategy<Object>
     The deployment strategy to use to replace existing pods with new ones.

   template<Object> -required-
     Template describes the pods that will be created. The only allowed
     template.spec.restartPolicy value is "Always".

So based on this we know it will be:

spec:
  replicas: 3
  template:
    < all-of-our-pod-specific-things-here >

Since I'm not sure what you're having issues with, this is just some general tips and may or may not be precisely the help you're looking for. But hopefully it's still useful info.

3

u/Rage1337 Apr 27 '24

Me, using OCP on a more ore less professional level for years now, learning about „oc explain“. Thank you very much, fellow human.

1

u/triplewho Red Hat employee Apr 27 '24

Hey, no worries. Glad you found it useful! I have accumulated decent collection of OpenShift related videos now. Hopefully there’s so more useful info there for you too!

https://youtube.com/playlist?list=PLSsjlbQ1lz_IaulDBxsNboePeoxfRsV98&si=nLU5VABtx9xKSUbA

2

u/Narrow_Spot_1803 Apr 28 '24

To generate yaml files,it is easier directly with cli commands to obtain the yaml, using --dry-run option.

Example: oc create deployment example --image <some-image> --dry-run=server --replicas 2 -o yaml

Then you filter out what you need.

Also, there are already some default templates in OCP and you can create a test project based on a template and extract many yaml fields.

My advice for him is to start with DO180 and then to do DO280.

Helpful tips to edit yaml file with vi : https://kube.academy/courses/how-to-prepare-for-the-cka-exam/lessons/editing-yaml-with-vim

5

u/Discomfited8812 Apr 27 '24

Day in and day out I find myself using tools like yq and jq as well as doing dry runs with the create command with -o yaml. I will however use the GUI for shortcuts like copying yaml files that are already created and stripping the managed fields and namespace values out of it.

3

u/Rhopegorn Apr 27 '24

Perhaps if you use vsCode extensions it might be easier for you, but you will eventually have to grasp the formatting rules.

As u/triplewho already pointed out, oc describe and explain should be your new BFFs.

You might also want to look at podman pod create and generate kube, to see if you find them useful at all.

Best of luck on your endeavour. 🍀

3

u/laurpaum Apr 27 '24

OpenShift provides a lot of imperative commands that can help avoid writing long yaml. For instance, the oc new-app command generates a full deployment yaml for, and oc set command are by far more efficient that directly editing yaml definitions.