Kubernetes Chapter YAML

For kubernetes resources can use to load yaml markup language, self-definition:

YAML (/ jæməl /, similar to the tail camel camels) is a highly readable, the data used to express serialization format. YAML reference to other languages, including: C, Python, Perl, and get inspiration from XML, e-mail data format (RFC 2822) in. Clark Evans in 2001 published the first language [1], in addition Ingy döt Net co-designer and Oren Ben-Kiki is this language [2]. There have been several current programming or scripting language support (or resolve) this language. 

YAML is "YAML Is not a Markup Language" (YAML is not a markup language) is a recursive acronym. In the development of the language, YAML meant in fact: "Yet Another Markup Language" (still a markup language) [3], but in order to emphasize the language as a data center, rather than as markup language focus, with the reverse Abbreviations renamed.

Use YAML is used to define k8s will give you some benefits, including:

  • Convenience: You will no longer need to add a lot of command line parameters to execute the command
  • Maintainability: YAML files can be source control, you can track every operation
  • Flexibility: You will be able to create more complex than the command line structure by YAML

YAML is a superset of JSON, it means that any valid JSON file is also a valid YAML file. So on the one hand, if you know JSON, you're just going to write your own YAML (instead of reading someone else's) it can be had. On the other hand, it is less likely, unfortunately, even though you try to go online to find examples, but they are usually not JSON, so we may need to get used to it. However, there may be more convenient in the case of JSON, so you will be very happy you know JSON.

Fortunately, YAML only two types of structure you need to know:

  • Lists
  • YAML lists is a sequence of objects
  • Maps
  • Maps will let you key combination, you can be more convenient to set configuration information

  

View a list of resources pod

[root @ Kube ~] # kubectl GET POD nginx-App-7756966bc9-qrksb -o yaml 
    // This is a run through kubectl run way pod, then we can manually define a yaml similar to this then generates the configuration file to load POD
apiVersion: V1 kind: Pod Metadata: creationTimestamp: "2019-07-16T06: 39: 02Z" generateName: Nginx-App-7756966bc9- Labels: POD the hash-Template-: 7756966bc9 RUN: Nginx-App name: Nginx-APP- qrksb-7756966bc9 namespace: default ownerReferences: - apiVersion: Apps / v1 blockOwnerDeletion: to true the Controller: to true kind: ReplicaSet name: nginx-App-7756966bc9 uid: 51997507-0ad5-4f71-86db-3ad6eff70171 resourceVersion: "603 662" selfLink: /api/v1/namespaces/default/pods/nginx-app-7756966bc9-qrksb uid: 7035cfbd-a8f3-45a9-933c-4ce1cef45183 spec: containers: - image: nginx:alpine imagePullPolicy: IfNotPresent name: nginx-app ports: - containerPort: 80 protocol: TCP resources: {} terminationMessagePath: /dev/termination-log terminationMessagePolicy: File volumeMounts: - mountPath: /var/run/secrets/kubernetes.io/serviceaccount name: default-token-bsthb readOnly: true dnsPolicy: ClusterFirst enableServiceLinks: true nodeName: kube.node1 priority: 0 restartPolicy: Always schedulerName: default-scheduler securityContext: {} serviceAccount: default serviceAccountName: default terminationGracePeriodSeconds: 30 tolerations: - effect: NoExecute key: node.kubernetes.io/not-ready operator: Exists tolerationSeconds: 300 - effect: NoExecute key: node.kubernetes.io/unreachable operator: Exists tolerationSeconds: 300 volumes: - name: default-token-bsthb secret: defaultMode: 420 secretName: default-token-bsthb status: conditions: - lastProbeTime: null lastTransitionTime: "2019-07-16T06:39:02Z" status: "True" type: Initialized - lastProbeTime: null lastTransitionTime: "2019-07-16T06:39:36Z" status: "True" type: Ready - lastProbeTime: null lastTransitionTime: "2019-07-16T06:39:36Z" status: "True" type: ContainersReady - lastProbeTime: null lastTransitionTime: "2019-07-16T06:39:02Z" status: "True" type: PodScheduled containerStatuses: - containerID: docker://6f50a8038d1f9b484c3af46fa21ef0bdce963b95c4f7f5980302bc70ca46eea6 image: nginx:alpine imageID: docker-pullable://nginx@sha256:17bd1698318e9c0f9ba2c5ed49f53d690684dab7fe3e8019b855c352528d57be lastState: {} name: nginx-app ready: true restartCount: 0 state: running: startedAt: "2019-07-16T06:39:36Z" hostIP: 10.2.61.22 phase: Running podIP: 10.244.2.7 qosClass: BestEffort startTime: "2019-07-16T06:39:02Z" [root@kube ~]#

  

Our analysis is carried out for yaml format:

#maps is key | value combination, list is key [args, args, a combination of a plurality of items] with a dash (-) at the beginning 
apiVersion: // Maps V1 kind: // Pod Maps Metadata:       name: // RSS-Site Maps Labels: App: Web / Maps spec: // Maps Containers: // List name - name: Front-End // child List parameter is Maps Image: Nginx // List parameter subkeys are Maps the ports: - containerPort: 80 // list parameters subkey Maps - name: RSS-Reader Image: nickchase / RSS-PHP-Nginx: V1 the ports: - containerPort: 88

  

Create a simple file yaml

root@kube test]# cat pod-demo.yaml 
apiVersion: v1
kind: Pod
metadata:
   name: pod-test
   namespace: default
   labels:
     app: myapp
     tier: frontend
spec:
   containers:
     - name: mytest
       image: nginx:latest
            
[root@kube test]# 
[root@kube test]# kubectl create -f pod-demo.yaml
pod/pod-test created
[root@kube test]# kubectl get pods
NAME                         READY   STATUS              RESTARTS   AGE
busy1-78c9f4b47-pm2qx        0/1     CrashLoopBackOff    22         100m
busy2-7f9dbf96d6-2d778       1/1     Running             0          2d23h
busy3-9877c76bf-ts5rl        1/1     Running             0          2d23h
nginx-7bb7cd8db5-6sgvp       1/1     Running             0          3d
nginx-app-54c844949f-6zlmr   0/1     ContainerCreating   0          41h
nginx-app-54c844949f-n82d6   1/1     Running             0          2d
nginx-app-54c844949f-xmkb8   1/1     Running             0          2d
nginx-app-7756966bc9-qrksb   1/1     Running             0          2d2h
pod-test                     0/1     ContainerCreating   0          1s
[root@kube test]# 

  

[root@kube test]# kubectl describe pod pod-test
Name:         pod-test
Namespace:    default
Priority:     0
Node:         kube.node1/10.2.61.22
Start Time:   Thu, 18 Jul 2019 16:44:23 +0800
Labels:       app=myapp
              tier=frontend
Annotations:  <none>
Status:       Running
IP:           10.244.2.12
Containers:
  mytest:
    Container ID:   docker://4e40fc5b6cae440881cea707b79c2d17692c47d75df69a571fa0e7d57dff5e3a
    Image:          nginx:latest
    Image ID:       docker-pullable://nginx@sha256:b4b9b3eee194703fc2fa8afa5b7510c77ae70cfba567af1376a573a967c03dbb
    Port:           <none>
    Host Port:      <none>
    State:          Running
      Started:      Thu, 18 Jul 2019 16:44:46 +0800
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-bsthb (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             True 
  ContainersReady   True 
  PodScheduled      True 
Volumes:
  default-token-bsthb:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-bsthb
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type    Reason     Age   From                 Message
  ----    ------     ----  ----                 -------
  Normal  Scheduled  62s   default-scheduler    Successfully assigned default/pod-test to kube.node1
  Normal  Pulling    61s   kubelet, kube.node1  Pulling image "nginx:latest"
  Normal  Pulled     40s   kubelet, kube.node1  Successfully pulled image "nginx:latest"
  Normal  Created    40s   kubelet, kube.node1  Created container mytest
  Normal  Started    39s   kubelet, kube.node1  Started container mytest
[root@kube test]# 

  

 

[root@kube ~]# kubectl api-versions
admissionregistration.k8s.io/v1beta1
apiextensions.k8s.io/v1beta1
apiregistration.k8s.io/v1
apiregistration.k8s.io/v1beta1
apps/v1
apps/v1beta1
apps/v1beta2
authentication.k8s.io/v1
authentication.k8s.io/v1beta1
authorization.k8s.io/v1
authorization.k8s.io/v1beta1
autoscaling/v1
autoscaling/v2beta1
autoscaling/v2beta2
batch/v1
batch/v1beta1
certificates.k8s.io/v1beta1
coordination.k8s.io/v1
coordination.k8s.io/v1beta1
events.k8s.io/v1beta1
extensions/v1beta1
networking.k8s.io/v1
networking.k8s.io/v1beta1
node.k8s.io/v1beta1
policy/v1beta1
rbac.authorization.k8s.io/v1
rbac.authorization.k8s.io/v1beta1
scheduling.k8s.io/v1
scheduling.k8s.io/v1beta1
storage.k8s.io/v1
storage.k8s.io/v1beta1
v1
[root@kube ~]# kubectl explain pods
KIND:     Pod
VERSION:  v1

DESCRIPTION:
     Pod is a collection of containers that can run on a host. This resource is
     created by clients and scheduled onto hosts.

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's metadata. More info:
     https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata

   spec	<Object>
     Specification of the desired behavior of the pod. More info:
     https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status

   status	<Object>
     Most recently observed status of the pod. This data may not be up to date.
     Populated by the system. Read-only. More info:
     https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status

[root@kube ~]# 

  

 

 

Guess you like

Origin www.cnblogs.com/zy09/p/11208338.html