Defining Multiple Objects in the Same YAML file

Learn how to combine all the services, API's and replicaSets into one YAML file.

Combining multiple YAML files into one file#

All the YAML files defined in the previous lesson for pods, services, and API work together. But having four YAML definitions is confusing. It would get even more confusing later on since we are going to add more objects to the stack. Things would be much simpler and easier if we would move all the objects we created thus far into a single YAML definition. Fortunately, that is very easy to accomplish.

Let’s take a look at yet another YAML file go-demo-2.yml in the code playground at the end of the lesson. It is the same as the contents of the previous four YAML files combined. The only difference is that each object definition is separated by three dashes (---).

We will create the objects defined in the go-demo-2.yml in this lesson:

Create 'go-demo-2

The output of the latter command is as follows.

Output of above command

The two ReplicaSets and the two Services were created, and we can rejoice in replacing four files with one.

Finally, to be on the safe side, we’ll also double-check that the stack API is up-and-running and accessible.

Calling 'go-demo-2-api'

The response is 200 indicating that everything works as expected.

Try it yourself#

The list of all the commands used in this lesson is as follows.

List of all the commands used in this lesson

You can practice the commands in the following code playground by pressing the Run button and waiting for the cluster to set up.

/
go-demo-2.yml
Defining multiple objects using single YAML file
Creating the Split API Pods
Discovering Services
Mark as Completed
Report an Issue