table of Contents
Resource object
- workload:Pod, ReplicaSet, Deployment, StatefulSet, DaemonSet, Job, Cronjob
- Service Discovery and balanced: Service, Ingress
- Configuration and storage: Volume, CSI, ConfigMap, Secret, DownwardAPI
- Cluster-level resources: Namespace, Node, Role, ClusterRole, RoleBinding, ClusterRoleBinding
- Metadata type resources: HPA, PodTemplate, LimitRange
Ways to create resources
apiserver: only accepts resource definition in JSON format;
Provide configuration list using yaml format, apiserver can be automatically converted to JSON format, and then execution;
Most resource configuration list:
- apiVersion: group/version
$ kubectl api-versions
- kind resource category (pod, service, deployment, etc.)
- metadata: Metadata
name
Under the same namespace name must be unique
namespace
namespace
labels
labels, each label resource can have
annotations resource comment
3.spec: user desired target state, disired state
4.status: current status, should be infinitely close to spec state, current state, this field is maintained by kubernetes cluster; users can not customize;
Help command list
Can kubectl explain
help to see the list of required
Such as:
[root@master ~]# kubectl explain pod
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>(k8s集群当前所处状态,应无限向目标状态靠拢,只读的,不受人为控制)
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
See here is the first layer pod, such as the information == metadata == want, continue to view directly pod.metadata
Such as:
[root@master ~]# kubectl explain pod.metadata
KIND: Pod
VERSION: v1
RESOURCE: metadata <Object>
DESCRIPTION:
Standard object's metadata. More info:
https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
ObjectMeta is metadata that all persisted resources must have, which
includes all objects users must create.
FIELDS:
annotations <map[string]string>
Annotations is an unstructured key value map stored with a resource that
may be set by external tools to store and retrieve arbitrary metadata. They
are not queryable and should be preserved when modifying objects. More
info: http://kubernetes.io/docs/user-guide/annotations
clusterName <string>
The name of the cluster which the object belongs to. This is used to
distinguish resources with same name and namespace in different clusters.
This field is not set anywhere right now and apiserver is going to ignore
it if set in create or update request.
creationTimestamp <string>
CreationTimestamp is a timestamp representing the server time when this
object was created. It is not guaranteed to be set in happens-before order
across separate operations. Clients may not set this value. It is
represented in RFC3339 form and is in UTC. Populated by the system.
Read-only. Null for lists. More info:
https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
.......
.......
# 太多就不复制了
So is the case;
- kubectl explain pod.spec
- kubectl explain pod.status
Category:
there will be a corresponding field in each, after they,
Types of | Explanation | For example |
---|---|---|
string | String | String |
[]string | List of strings | You need to fill an array of type String |
map[string]string | View string | There are many needs k: v type of data |
Object | Objects | DESCRIPTION need a lower field nested |
[]Object | Object List | A plurality of instructions can be nested at a required field |
- required - | Required | When this occurs when this parameter must be filled |
Create a test list
Create a pod-demo.yaml
file, reads as follows:
- Precautions
- Note case
- List need to add "-" generally use the same level
[root@master manifests]# cat pod-demo.yaml
apiVersion: v1
kind: Pod
metadata:
name: pod-demo
namespace: default
labels:
app: myapp
tier: frontend
spec:
containers:
- name: myapp
image: ikubernetes/myapp:v1
- name: busybox
image: busybox:latest
command:
- "/bin/sh"
- "-c"
- "sleep 3600"
Use kubectl create
the command to load the file operations
[root@master manifests]# kubectl create -f pod-demo.yaml
pod/pod-demo created
[root@master manifests]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
pod-demo 2/2 Running 0 20s 10.244.3.8 node01.kubernetes <none> <none>
We can see already properly started.
If you want to delete this pod, is used kubectl delete
to to pod-demo.yaml
operate may be;
[root@master manifests]# kubectl delete -f pod-demo.yaml
pod "pod-demo" deleted
How resources are three ways to create
For kubernetes
resources, there are three ways to create
1. The first is the last article, and use the command to create
2, the second is demonstrated in this article, configuration list style usage. Also known as command-list resources
3, the third is declarative resource list, a third way that is similar to the second list.
Declarative is to ensure that the resources we declare a state of change as much as possible, and we are ready to change our statement and application at any time.