What is the best way to get a sample k8 yaml to edit as per requirement?

8/21/2021

In declarative approach , what is the best way to get a default/sample yaml file which we can edit on vi as per our requirement , do we need to copy it everytime from k8 doc ?

-- Abdul Mohsin
kubernetes

3 Answers

8/21/2021

yes, k8s documentation is the best place to start with a default yaml file for the required setup as its up-to-date and you are sure that it works without any surprises for beginners.

-- Ravi Kumar CH
Source: StackOverflow

8/21/2021

Some resource samples can be created with kubectl create <resource type> <resource name> --dry-run=client -o yaml. To see which resource can be created run kubectl create --help.

For example, to create a deployment named demo with nginx image, run:

kubectl --namespace=default create deploy demo --image=nginx --port=80 --dry-run=client -o yaml

It generates:

apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: demo
  name: demo
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: demo
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: demo
    spec:
      containers:
      - image: nginx
        name: nginx
        ports:
        - containerPort: 80
        resources: {}
status: {}

Another example with Ingress. Write YAML definition to demo-ingress.yaml

kubectl create ingress demo --rule="foo.com/api=api-svc:8080,tls=my-cert" --dry-run=client -o yaml > demo-ingress.yaml
-- Moazzem Hossen
Source: StackOverflow

8/21/2021

The VSCode Kubernetes plugin includes scaffolds for the major object types. I'm guessing there are similar plugins for other editors.

-- coderanger
Source: StackOverflow