others-How to create yaml quickly in kubernetes?
1. Purpose
In this post, I would demo how to create yaml for pod quickly in kubernetes.
2. Environment
- Kubernetes
3. The solution
3.1 Copy from k8s official website
If you can access the k8s official website, you can try to access:
https://kubernetes.io/docs/concepts/workloads/pods/init-containers/
Then find the pod yaml template and copy the content of the yaml:
3.2 Create yaml template by using kubectl
We can use kubectl to create the yaml template as follows:
$ kubectl run nginx --image=nginx --dry-run -o yaml
You would get this:
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: nginx
name: nginx
spec:
containers:
- image: nginx
name: nginx
resources: {}
dnsPolicy: ClusterFirst
restartPolicy: Always
status: {}
controlplane $
The options are explained as follows:
--dry-run
means this command would not execute, only dry run-o yaml
export the result as yaml format
4. Summary
In this post, I tried to explain the ways to create yaml in Kubernetes.