First, Kubernetes common resources
The following is an object in Kubernetes, which can be configured as an API type in a Yaml file.
Category |
Name |
Workload-based resource objects |
Pod replicaset replicationcontroller deployments statefulsets daemonset Job cronjob |
Service Discovery and load balancing |
Service Ingress |
Configuration and Storage |
Volume, persistent Volume, CSl, Configmap, secret |
Cluster resources |
Namespace Node Role clusterrole rolebinding clusterrolebinding |
Meta Data resources |
HPA podtemplate Limitrang |
Ii. understanding the objects in Kubernetes
In the Kubernetes system, the Kubernetes object is a persisted entry. Kubernetes uses these entries to represent the state of the entire cluster. In particular, they describe the following information:
- What container applications are running (and on which Node)
- Resources that can be used by the app
- Strategies for how applications behave, such as restart policies, upgrade strategies, and fault tolerance strategies
The Kubernetes object is a "target record"--once the object is created, the Kubernetes system will continue to work to ensure that the object exists. By creating an object, you can effectively tell the Kubernetes system what the cluster workload looks like, which is the desired state of the Kubernetes cluster.
Working with Kubernetes objects-whether created, modified, or deleted-requires the use of the Kubernetes API. When using the kubectl
command-line interface, for example, the CLI uses the necessary Kubernetes API calls, or it can use the Kubernetes API directly in the program.
Third, the object of the spec and state
Each Kubernetes object contains two nested object fields, which are responsible for managing the configuration of objects: Object spec and object status. Spec must provide, which describes the desired state of an object-the characteristics of the desired object. Status describes the actual state of the object, which is provided and updated by the Kubernetes system. At any given moment, the Kubernetes control plane is active, managing the actual state of the object to match the state we expect.
For example, the Kubernetes Deployment object can represent an application running in a cluster. When creating a Deployment, you may need to set the Deployment spec to specify that the app requires 3 copies to run. The Kubernetes system reads the Deployment spec and launches 3 instances of the application that we expect-updating the status to match the spec. If there are failures (a state change) in those instances, the Kubernetes system responds to the inconsistency between spec and state by correcting-in this case, a new instance is started to replace.
Iv. Defining resources Using YAML
When creating a Kubernetes object, you must provide a spec for the object that describes the expected state of the object and some basic information about the object (for example, name). When an object is created using the Kubernetes API (or created directly, or based on kubectl
), the API request must contain the JSON-formatted information in the request body. More commonly, this information needs to be provided in the. yaml file for Kubectl. kubectl
this information is converted to JSON format when the API request is executed. As an example:
[[email protected] ~]# vim my-demo.yaml apiVersion:v1kind:Podmetadata:name: My -demo namespace:default labels:name:myapp tier:appfrontspec:containers : - Name:myapp image:ikubernetes /myapp:v1 - name:busybox image:busybox command: - " /bin/sh " -" -c "-" sleep 3600 " [[email protected] -master ~]# kubectl apply-f my-demo.yaml
In the file that corresponds to the Kubernetes object you want to create .yaml
, you need to configure the following fields:
apiVersion
-The version of the Kubernetes API used to create the object
kind
-The type of object you want to create
metadata
-data that helps identify object uniqueness, including a name
string, UID, and optionalnamespace
You can view deployment resource-defined fields in a kubectl explain way
[[Email protected] ~]# kubectl Explain deployment #查看deployment的定义字段, contains the require tag is a must field KIND:DeploymentVERSION:extensions/v1beta1description:deprecated-This group version of Deployment was deprecated by apps/v1beta2/deployment. See the Release Notes for Moreinformation. Deployment Enables declarative updates forPods and ReplicaSets.FIELDS:apiVersion<string>Apiversion defines the versioned schema of this representation of aObject. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. moreInfo: https://git.k8s.io/community/contributors/devel/api-conventions.md#resourcesKind<string>Kind is astringValue representing the REST resource thisObjectrepresents. Servers may infer this from the endpoint, the client submits requests to. cannot be updated. In CamelCase. moreInfo: https://Git.k8s.io/community/contributors/devel/api-conventions.md#types-kindsmetadata<Object> StandardObjectmetadata. Spec<Object>specification of the desired behavior of the Deployment. Status<Object>Most recently observed status of the Deployment.
Kubernetes Learning Path (11) resource list definition