k8s中大部分资源清单包含以下5个字段:
1.apiVersion : group/version
[root@master ~]# kubectl api-versions
包含:
admissionregistration.k8s.io/v1beta1
apiextensions.k8s.io/v1beta1
apiregistration.k8s.io/v1
apiregistration.k8s.io/v1beta1
apps/v1
apps/v1beta1
apps/v1beta2
authentication.k8s.io/v1
authentication.k8s.io/v1beta1
authorization.k8s.io/v1
authorization.k8s.io/v1beta1
autoscaling/v1
autoscaling/v2beta1
autoscaling/v2beta2
batch/v1
batch/v1beta1
certificates.k8s.io/v1beta1
coordination.k8s.io/v1beta1
events.k8s.io/v1beta1
extensions/v1beta1
networking.k8s.io/v1
policy/v1beta1
rbac.authorization.k8s.io/v1
rbac.authorization.k8s.io/v1beta1
scheduling.k8s.io/v1beta1
storage.k8s.io/v1
storage.k8s.io/v1beta1
v1
2.kind: 资源类别
包含:Pod、ReplicaSet、Deployment、StatefulSet、DaemonSet、Job、Cronjob、Service、Ingress、Volume。。。等
3.metadata:元数据
name
namespace
labels
annotations
每个资源的引用方式:
/api/GROUP/VERSION/namespace/NAMESPACE/TYPE/NAME
4. spec:期望的状态 ,disired state
5. status:当前状态 current state,本字段由kubernetes集群维护
(可以通过kubectl explain 来查找定义)
eg:
自定义一个简单的yaml文件
vim 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"
kubectl create -f pod-demo.yaml
在一个pod中自定义两个容器同时running
kubectl delete pods pod-demo删除这个pod
或者kubectl delete -f pod-demo.yaml