简体   繁体   中英

Whats the best way to compose yaml file for Kubernetes resource?

I'm working on composing yaml file for installing Elasticsearch via the ECK operator (CRD).

Its documented here - https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-elasticsearch-specification.html

As one goes through the sub-links, you will discover there are various pieces through which we can define the configuration of Elasticsearch.

The description of the CRD is contained here, but this is not easy to read - https://download.elastic.co/downloads/eck/1.0.0-beta1/all-in-one.yaml

I'm curious how do Kubernetes developers understand various constructs of yaml file for a given kubernetes resource?

Docs

In general, if it's a standard resource, the best way is to consult the official documentation for all the fields of the resource.

You can do this with kubectl explain . For example:

kubectl explain deploy
kubectl explain deploy.spec
kubectl explain deploy.spec.template

You can find the same information in the web-based API reference .

Boilerplate

For some resources, you can use kubectl create to generate the YAML for a basic version of the resource, which you can then use as a starting point for your own customisations.

For example:

kubectl create deployment --image=nginx mydep -o yaml --dry-run >mydep.yaml

This generates the YAML for a Deployment resource and saves it in a local file. You can then customise the resource from there.

The --dry-run option causes the generated resource definition to not be submitted to the API server (so it won't be created) and the -o yaml option outputs the generated definition of the resource in YAML format.

Other common resources for which this is possible include:

  • (Cluster)Role
  • (Cluster)RoleBinding
  • ConfigMap
  • Deployment
  • Job
  • PodDisruptionBudget
  • Secret
  • Service

See kubectl create -h .

Another approach to write yml files for Kubernetes resources could be to use kubernetes plugin which should be available for most of the IDEs.

For example, For Intellij, following is link for Kubernetes plugin. This link also explains which all features this plugin provides:

https://www.jetbrains.com/help/idea/kubernetes.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM