Tom Gallacher
Mar 11 · 2 min read
Photo by Michael Longmire on Unsplash

Ever wanted to know a field in your Kubernetes yaml definition, but found it ridiculously difficult to find out what it means or even how to use it 😥?

kubectl is to the rescue!

To get started we can familiarise ourselves with what API resources we have available to use. To do this we can run kubectl api-resources, looking at the output of this command we can start to paint a picture of what resources our cluster is composed of.

Let’s take the deployment resource as our first example. Interestingly we can see that multiple definitions exist for this resource, once for the API Group extensions and one for apps. We will find out why this is the case later on 🤯!

So how do we write a yaml definition for this deployment? It’s possible to get examples for the Kubernetes documentation — personally I always find this too difficult to navigate, instead, it is possible to interrogate the API server’s OpenAPI specification using kubectl.

The command in question is kubectl explain, so let’s give this a whirl 😜!

$ kubectl explain deployment

This will show us all of the keys that are available to use at the top level!

KIND:     Deployment
VERSION: extensions/v1beta1
DESCRIPTION:
DEPRECATED - This group version of Deployment is deprecated by
apps/v1beta2/Deployment. See the release notes for more information.
Deployment enables declarative updates for Pods and ReplicaSets.
FIELDS:
apiVersion <string>
APIVersion defines the versioned schema of this representation of an
object. Servers should convert recognized schemas to the latest internal
value, and may reject unrecognized values. More info:
https://git.k8s.io/community/contributors/devel/api-conventions.md#resources
kind <string>
Kind is a string value representing the REST resource this object
represents. Servers may infer this from the endpoint the client submits
requests to. Cannot be updated. In CamelCase. More info:
https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds
metadata <Object>
Standard object metadata.
spec <Object>
Specification of the desired behavior of the Deployment.
status <Object>
Most recently observed status of the Deployment.

If you really want to dive deep you can add a “recursive” parameter!

kubectl explain deployment --recursive

But I will omit the output so you can check it out yourself! (Hint: the output is longer than this post 😈)

Written by Tom Gallacher — Staff Engineer at YLD.


YLD Blog

YLD's latest thoughts on Software Engineering, Design, leadership and Digital Products

Tom Gallacher

Written by

🏎️🛣️🚴👨‍💻🍺. Linux performance privateer & DevOps extraordinaire, Often seen happily writing code without any knowledge of his surroundings. @YLDio

YLD Blog

YLD Blog

YLD's latest thoughts on Software Engineering, Design, leadership and Digital Products

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade