只需要在object字段里面添加类型x-kubernetes-preserve-unknown-fields: true就可以
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: mines.test.io
spec:
group: test.io
versions:
- name: v1
served: true
storage: true
schema:
openAPIV3Schema:
type: object
properties:
spec:
type: object
properties:
template:
type: object
x-kubernetes-preserve-unknown-fields: true
replicas:
type: integer
status:
type: object
properties:
label:
type: string
scope: Namespaced
names:
plural: mines
singular: mine
kind: Mine
shortNames:
- mn
然后创建这个资源的时候就可以直接使用podtemplate
apiVersion: test.io/v1
kind: Mine
metadata:
name: test
labels:
app: test
spec:
template:
metadata:
labels:
app: test
spec:
containers:
- name: nginx
images: nginx:1.12.2
ports:
- containerPort: 8080
replicas: 3
spec的struct定义为
type SpecMine struct {
PodTemplate v12.PodTemplateSpec `json:"template"`
Replicas int32 `json:"replicas"`
}
就可以获取到yaml里面设置的pod的template


![k8s crd如何使用map[string]interface{} k8s crd如何使用map[string]interface{}](http://www.mshxw.com/aiimages/31/990434.png)
