例子:自定义crd

写一个crd资源

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# cat custom-res-def.yaml
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: libin.meitu.k8s.io
spec:
group: meitu.k8s.io
versions:
- name: v1
served: true
storage: true
scope: Namespaced
names:
plural: libin
singular: libin
kind: Libin
shortNames:
- lib

# kubectl apply -f custom-res-def.yaml
customresourcedefinition.apiextensions.k8s.io/libin.meitu.k8s.io created

查看crd定义

1
2
3
# kubectl get crd | grep libin
NAME CREATED AT
libin.meitu.k8s.io 2020-12-01T09:11:32Z

创建crd资源对象

1
2
3
4
5
6
7
8
9
10
11
12
# cat custom-res-object.yaml
apiVersion: meitu.k8s.io/v1
kind: Libin
metadata:
name: object-libin
namespace: ops
spec:
name: "李彬"
func: "SRE"

# kubectl apply -f custom-res-object.yaml
libin.meitu.k8s.io/object-libin created

查看创建的对象

1
2
3
4
# kubectl get libin -n ops
# kubectl get lib -n ops
NAME AGE
object-libin 1h