Kubernetes Resource Creation YML syntax

Source: Internet
Author: User
Tags base64 docker registry

Objective

In the kubernetes, most of our resources are created through

1 Kubelet create-f Resource.yaml

Just opened to see the time inevitably some confused, do not understand grammar, do not know how to write; Today this article introduces Kubernetes construct syntax.

Construct syntax is actually the Kubelet format into the API post data, submitted to Apiserver, so here support Yaml,json two kinds of data structure files.

Pod Resources
1234567891011121314151617181920212223242526272829 APIVERSION:V1 Specifies the API version, which must be kind:pod in Kubectl apiversion to specify the role/type of the resource to be created metadata: the resource's metadata/attribute name:test the name of the resource, Must be unique in the same namespace labels: sets the label of the resource Sex:boy the key/value structure exists Age:18spec: #specification of the resource content Specifies the contents of this resource restartpolicy:never indicates that the container is only run once, the default K8s policy, when this container exits, immediately creates an identical container volumes: Define a set of mounted devices-name:volume Define the name of a mounted device Hostpath:/data/www/html mount Device Type Hostpath, the path is the/data/www/html under the host, here the device type supports many kinds of containers: the container in the specified resource-name: Container1 Container name Image: The mirror address used by the "Docker.coocla.org/ubuntu:last" container volumemounts:-Mountpath:/mnt mount to a path in the container under name: Volume mount device name, with volumes[*].name need to correspond livenessprobe: container health monitoring httpget:http form monitoring, return 200-399 between, then think container normal path:/healthport: 8080initialdelayseconds:15 indicates how long the first detection starts after the container starts Timeoutseconds:1 detection Timeout env: Specifies the environment variable in the container-name:str variable name value: "Hello The value of the "World" variable Command: ["/bin/bash", "-C"] overrides the entrypoint in the container, corresponding to the Entrypointargs in dockefile: ["/bin/echo", "$ (str)"] Corresponds to the cmd parameter in Dockerfile

Health monitoring also supports a different approach:

123456 EXEC: The method of executing the command is monitored, if its exit code is not 0, the container is considered normal command:-cat-/tmp/healthinitialdelayseconds:15timeoutseconds:1

Syntax parameters for Replicationcontroller
1234567891011121314 Apiversion:v1kind:replicationcontrollermetadata:name:nginxspec:replicas:2 Specify the number of pods in RC Template: Specify the templates for pods in RC, The pods in RC are created by this template metadata: Specify the metadata for the pod in RC, note that there is no need to specify the name of the pod, which is generated by RC copy labels:app:nginxspec:container:-name: Nginximage:nginx
Service
123456789101112131415 ApiVersion:v1kind:Servicemetadata:name:nginxsvclabels:app:nginxspec: Specify the contents of the Service ports: Map List-port:80 The port of the service POROTOCAL:TCP the protocol type of the map, supports tcp/udptargetport:80 mapping to the pod of the port name:www.baidu.com the name of the map selector: match Port:80app: Nginx matches the pod with the app Nginx,port 80 in the label
Secret
123456789101112131415 Apiversion:v1kind:secretmetadata:name:mysecrettype:0paque defines the type of secret, which supports three types of password:xxx|base64 to key/ Value in the form of a definition, value needs to be Base64 encoded, after secret is mounted in container, will be a key as the file name, value values are base64 decoded as the content, As a file exists in container username:xxx|base64---type:kubernetes.io/service-account-token the second secret type, used as token to create the service account, Used as authentication for interprocess communication---type:kubernetes.io/dockercfg Third secret type, used as authentication data:.dockercfg for Docker registry in the creation of container: ' Cat ~/. dockercfg | Base64 '

The above is part of the resource parameters, of course, there are more parameters can be specified, and more resources can be created by defining construct.

Kubernetes Resource Creation YML syntax

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.