Configuring complex environments

At the Controls

Validating Values

The validation of certain values with the length function can be quite useful:

yq eval ".spec.containers[].name | length" pod.yaml

A YAML template can also be easily modified by yq to create configurations for different environments. For example, if you want to insert the hostname of your production database into the URL variable of the first container in the pod.yaml template, you can use:

yq eval '.spec.containers[0].env[0].value = "postgres:// prod.example.com:5431"' pod.yaml > prod-pod.yaml

To make sure the change is visible not just on the screen, the modified YAML document has been written to a new file named prod-pod.yaml, which now contains the modification, as shown with the command:

yq eval ".spec.containers[0].env[0].value" prod-pod.yaml
postgres://prod.example.com:5431

With Kubernetes, this function proves to be extremely useful, because you can use it to change existing configurations immediately. For example, you can simply forward the output of the Kubernetes kubectl tool with

yq (kubectl ... | yq eval ...)

and use kubectl apply to send the result directly back to Kubernetes.

The Author

Thorsten Scherf is the global Product Lead for Identity Management and Platform Security in Red Hat's Product Experience group. He is a regular speaker at various international conferences and writes a lot about open source software.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy ADMIN Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Jenkins Configuration as Code
    The move from Groovy scripts to Jenkins Configuration as Code simplifies the initialization of Jenkins and Jenkins plugins.
  • Verifying your configuration
    Automated acceptance testing is a powerful tool for catching problems related to misconfiguration. We'll show you how to implement your own acceptance testing environment with a free tool called goss.
  • Validating Docker containers
    A new test tool by Google lets you peek inside Docker containers, so you can make sure they hold exactly what you expect.
  • Policy rulesets in cloud-native environments
    What a user is allowed to do in a program is usually defined by a role model, which often poses numerous challenges, especially in the cloud or for infrastructure as code. The free Open Policy Agent offers a flexible way to manage user rights.
  • Incident response with Velociraptor
    The software incarnation of the feared predator in the Jurassic Park movies has been on the hunt for clues to cyberattacks and indicators of compromise. We show you how to tame the beast and use it for your own purposes.
comments powered by Disqus
Subscribe to our ADMIN Newsletters
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs



Support Our Work

ADMIN content is made possible with support from readers like you. Please consider contributing when you've found an article to be beneficial.

Learn More”>
	</a>

<hr>		    
			</div>
		    		</div>

		<div class=