This is the 10th day of my participation in The August Wenwen Challenge.
Notes for writing YAML
YAML is a compact, unmarked language.
Syntax format:
- Indentation indicates hierarchy
- The TAB character “TAB” is not supported. Space is used for indentation
- Usually two Spaces are indented at the beginning
- A character is indented by one space, such as a colon or comma
- “–” indicates the start of a file in YAML format
- “#” comments
1. YAML content parsing
The YAML content of deploying an application in K8S is roughly divided into two parts:
Controller definition: Defines controller properties
Controlled object: Pod template that defines container properties
Specific field meaning:
apiVersion | API version |
---|---|
kind | The resource type |
metadata | Resource metadata |
spec | Resource specification |
replicas | Copy number |
selector | Label selector |
template | Pod template |
metadata | Pod metadata |
spec | Pod specifications |
containers | The container configuration |
Create pods using YAML
apiVersion: v1
kind: Pod
metadata:
name: kube100-site
labels:
app: web
spec:
containers:
- name: front-end
image: nginx
ports:
- containerPort: 80
- name: flaskapp-demo
image: jcdemo/flaskapp
ports:
- containerPort: 500
Copy the code
ApiVersion: the value here is v1. This version number needs to be changed depending on the installed Kubernetes version and resource type. Remember that it is not written down.
Kind: Pod is created here. The resource type can be Deployment, Job, Ingress, Service, etc.
Metadata: Contains meta information about a Pod, such as name, namespace, and tag information.
Spec: Contains some container, storage, volume, and other parameters required by Kubernetes, as well as properties such as whether to restart the container if the container fails. The complete Kubernetes Pod properties can be found in the specific Kubernetes API.
2. Resource fields too many, remember how to do?
Many students YAML can’t write! The main reason is to use less, which is due to the composition of each resource, familiar with each resource application, will naturally write, but also do not have to wait to be familiar with a variety of resources, here teach you a few skills to help quickly start.
-
Use the run command to generate a deployment template
Kubectl create deployment nginx –image=nginx:1.14 -o yaml –dry-run> my-deploy.yaml
-
Run the get command to export the deployed yamL application
kubectl get my-deploy/nginx -o=yaml –export > my-deploy.yaml
-
If a field word is not remembered, refer to explain for more detailed help
kubectl explain pods.spec.containers