常用资源对象:
依据资源的主要功能作为分类标准,Kubernetes的API对象大体可分为五个类别,如下:
类型 | 名称 |
---|---|
工作负载(Workload) | Pod、ReplicaSet、Deployment、StatefulSet、DaemonSet、Job、Cronjob |
负载均衡(Discovery &LB) | Service、Ingress |
配置和存储(Config&Storage) | Volume、CSI、ConfigMap、Secret、DownwardAPI |
集群(Cluster) | Namespace、Node、Role、ClusterRole、RoleBinding、ClusterRoleBinding |
元数据(metadata) | HPA、PodTemplate、LimitRange |
对象资源格式:
Kubernetes API 仅接受及响应JSON格式的数据(JSON对象),同时,为了便于使用,它也允许用户提供YAML格式的POST对象,但API Server需要实现自行将其转换为JSON格式后方能提交
API Server接受和返回的所有JSON对象都遵循同一个模式,它们都具有kind和apiVersion字段,用于标识对象所属的资源类型、API群组及相关的版本
大多数的对象或列表类型的资源提供元数据信息,如名称、隶属的名称空间和标签等
spec则用于定义用户期望的状态,不同的资源类型,其状态的意义也各有不同,例如Pod资源最为核心的功能在于运行容器
而status则记录着活动对象的当前状态信息,它由Kubernetes系统自行维护,对用户来说为只读字段
配置清单示例:
[root@k8s-master ~]# kubectl get pod nginx-67685f79b5-8rjk7 -o yaml #获取该pod的配置清单
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: “2019-08-30T07:00:30Z”
generateName: nginx-67685f79b5-
labels:
pod-template-hash: 67685f79b5
run: nginx
name: nginx-67685f79b5-8rjk7
namespace: default
ownerReferences:
- apiVersion: apps/v1
blockOwnerDeletion: true
controller: true
kind: ReplicaSet
name: nginx-67685f79b5
uid: 6de479a9-52f6-4581-8e06-884a84dab593
resourceVersion: “244953”
selfLink: /api/v1/namespaces/default/pods/nginx-67685f79b5-8rjk7
uid: 0b6f5a87-4129-4b61-897a-6020270a846e
spec:
containers: - image: nginx:1.12
imagePullPolicy: IfNotPresent
name: nginx
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: default-token-s8mbf
readOnly: true
dnsPolicy: ClusterFirst
enableServiceLinks: true
nodeName: k8s-node1
priority: 0
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
serviceAccount: default
serviceAccountName: default
terminationGracePeriodSeconds: 30
tolerations:
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
- 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-s8mbf
secret:
defaultMode: 420
secretName: default-token-s8mbf
status:
conditions: - lastProbeTime: null
lastTransitionTime: “2019-08-30T07:00:30Z”