Version: v1.2

资源模板

KubeVela 可以以资源模板的方式直接部署任何 Kubernetes 对象。

如何使用

比如一个 Job。

  1. apiVersion: core.oam.dev/v1beta1
  2. kind: Application
  3. metadata:
  4. name: app-raw
  5. spec:
  6. components:
  7. - name: myjob
  8. type: k8s-objects
  9. properties:
  10. objects:
  11. - apiVersion: batch/v1
  12. kind: Job
  13. metadata:
  14. name: pi
  15. spec:
  16. template:
  17. spec:
  18. containers:
  19. - name: pi
  20. image: perl
  21. command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"]
  22. restartPolicy: Never
  23. backoffLimit: 4

也支持多个资源,但是要把你的主要工作负载放在第一个,KubeVela 的 traits 只会对第一个位置的 Kubernetes 对象生效。

  1. apiVersion: core.oam.dev/v1beta1
  2. kind: Application
  3. metadata:
  4. name: app-stateful-service
  5. spec:
  6. components:
  7. - name: my-sts
  8. type: k8s-objects
  9. properties:
  10. objects:
  11. - apiVersion: apps/v1
  12. kind: StatefulSet
  13. metadata:
  14. name: web
  15. spec:
  16. selector:
  17. matchLabels:
  18. app: nginx # has to match .spec.template.metadata.labels
  19. serviceName: "nginx"
  20. replicas: 3 # by default is 1
  21. template:
  22. metadata:
  23. labels:
  24. app: nginx # has to match .spec.selector.matchLabels
  25. spec:
  26. terminationGracePeriodSeconds: 10
  27. containers:
  28. - name: nginx
  29. image: k8s.gcr.io/nginx-slim:0.8
  30. ports:
  31. - containerPort: 80
  32. name: web
  33. volumeMounts:
  34. - name: www
  35. mountPath: /usr/share/nginx/html
  36. volumeClaimTemplates:
  37. - metadata:
  38. name: www
  39. spec:
  40. accessModes: [ "ReadWriteOnce" ]
  41. storageClassName: "my-storage-class"
  42. resources:
  43. requests:
  44. storage: 1Gi
  45. - apiVersion: v1
  46. kind: Service
  47. metadata:
  48. name: nginx
  49. labels:
  50. app: nginx
  51. spec:
  52. ports:
  53. - port: 80
  54. name: web
  55. clusterIP: None
  56. selector:
  57. app: nginx

属性说明

字段名称描述类型是否必填默认值
objectsKubernetes 资源列表[]K8s-Objecttrue

K8s-Object

列表中的元素为完整的 Kubernetes 资源结构体。