Kubenetes 资源清单定义入门

Kubernetes 常用资源

  • 资源  对象
  1. 工作负载型资源对象(workload): Pod  Replicaset  ReplicationController  Deployments StatefulSets Daemonset Job CronJob
  2. 服务发现及负载均衡: Service  Ingress
  3. 配置与存储:Volumes CSl  configmap  secret
  4. 集群资源:Namespace Node Role ClusterRole  RoleBinding  ClusterRoleBinding
  5. 元数据资源:HPA PodTemplate LimitRang

创建资源清单的方法

  • apiserver 仅接受JOSN格式的资源定义
  • yaml格式提供配置清单,apiserver自动转成json格式,然后在提交

大部分资源的配置清单:

  • apiVersion:  格式:group/version   查看 kubectl apiversion
  • kind:  Pod  Replicaset  Deployments ...
  • metadata: name namespace labels  annotations
  • spec: 定义用户期望状态  disired state
  • status: 定义当前状态 current state 该字段由kubenetes集群维护;

通过 yaml写一个简单的 pod应用

$ vim my-demo.yaml 

apiVersion: v1 kind: Pod metadata: name: my-demo namespace: default labels: name: myapp tier: appfront spec: containers: - name: myapp image: ikubernetes/myapp:v1 - name: busybox image: busybox command: - "/bin/sh" - "-c" - "sleep 3600"

$ kubectl apply -f my-demo.yaml

通过 kubectl  describe pods my-demo 查看集群信息

通过命令查看如何定义资源  (标有 required  意味是必填项)

$ kubectl  explain deployment
DESCRIPTION:
DEPRECATED - This group version of Deployment is deprecated by apps/v1beta2/Deployment. See the release notes for more information. Deployment enables declarative updates for Pods and ReplicaSets.

FIELDS:
   status       <Object>
     Most recently observed status of the Deployment.

   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 metadata.

   spec <Object>
     Specification of the desired behavior of the Deployment.

$  kubectl  explain deployment.spec

RESOURCE: spec <Object>

DESCRIPTION:
     Specification of the desired behavior of the Deployment.

    DeploymentSpec is the specification of the desired behavior of the Deployment.

FIELDS:
   paused       <boolean>
     Indicates that the deployment is paused and will not be processed by the
     deployment controller.

   revisionHistoryLimit <integer>
     The number of old ReplicaSets to retain to allow rollback. This is a
     pointer to distinguish between explicit zero and not specified.

   template     <Object> -required-
     Template describes the pods that will be created.

   rollbackTo   <Object>
     DEPRECATED. The config this deployment is rolling back to. Will be cleared
     after rollback is done.

   selector     <Object>
     Label selector for pods. Existing ReplicaSets whose pods are selected by
     this will be the ones affected by this deployment.

   strategy     <Object>
     The deployment strategy to use to replace existing pods with new ones.
......
原文地址:https://www.cnblogs.com/xzkzzz/p/9509465.html