diff --git a/docs/platform-engineers/kube/component.md b/docs/platform-engineers/kube/component.md deleted file mode 100644 index 1283da09ff7..00000000000 --- a/docs/platform-engineers/kube/component.md +++ /dev/null @@ -1,95 +0,0 @@ ---- -title: How-to ---- - -In this section, it will introduce how to use simple template to declare Kubernetes API resource into a component. - -> Before reading this part, please make sure you've learned [the definition and template concepts](../definition-and-templates.md). - -## Declare `ComponentDefinition` - -Here is a simple template based `ComponentDefinition` example which provides a abstraction for worker workload type: - -```yaml -apiVersion: core.oam.dev/v1beta1 -kind: ComponentDefinition -metadata: - name: kube-worker - namespace: default -spec: - workload: - definition: - apiVersion: apps/v1 - kind: Deployment - schematic: - kube: - template: - apiVersion: apps/v1 - kind: Deployment - spec: - selector: - matchLabels: - app: nginx - template: - metadata: - labels: - app: nginx - spec: - containers: - - name: nginx - ports: - - containerPort: 80 - parameters: - - name: image - required: true - type: string - fieldPaths: - - "spec.template.spec.containers[0].image" -``` - -In detail, the `.spec.schematic.kube` contains template of a workload resource and -configurable parameters. -- `.spec.schematic.kube.template` is the simple template in YAML format. -- `.spec.schematic.kube.parameters` contains a set of configurable parameters. The `name`, `type`, and `fieldPaths` are required fields, `description` and `required` are optional fields. - - The parameter `name` must be unique in a `ComponentDefinition`. - - `type` indicates the data type of value set to the field. This is a required field which will help KubeVela to generate a OpenAPI JSON schema for the parameters automatically. In simple template, only basic data types are allowed, including `string`, `number`, and `boolean`, while `array` and `object` are not. - - `fieldPaths` in the parameter specifies an array of fields within the template that will be overwritten by the value of this parameter. Fields are specified as JSON field paths without a leading dot, for example -`spec.replicas`, `spec.containers[0].image`. - -## Declare an `Application` - -Here is an example `Application`. - -```yaml -apiVersion: core.oam.dev/v1beta1 -kind: Application -metadata: - name: myapp - namespace: default -spec: - components: - - name: mycomp - type: kube-worker - properties: - image: nginx:1.14.0 -``` - -Since parameters only support basic data type, values in `properties` should be simple key-value, `: `. - -Deploy the `Application` and verify the running workload instance. - -```shell -kubectl get deploy -``` -```console -NAME READY UP-TO-DATE AVAILABLE AGE -mycomp 1/1 1 1 66m -``` -And check the parameter works. -```shell -kubectl get deployment mycomp -o json | jq '.spec.template.spec.containers[0].image' -``` -```console -"nginx:1.14.0" -``` - diff --git a/docs/platform-engineers/kube/trait.md b/docs/platform-engineers/kube/trait.md deleted file mode 100644 index 90b395d2b72..00000000000 --- a/docs/platform-engineers/kube/trait.md +++ /dev/null @@ -1,123 +0,0 @@ ---- -title: Attach Traits ---- - -All traits in the KubeVela system works well with the simple template based Component. - -In this sample, we will attach two traits, -[scaler](https://github.com/kubevela/kubevela/blob/master/charts/vela-core/templates/defwithtemplate/scaler.yaml) -and -[virtualgroup](https://github.com/kubevela/kubevela/blob/master/docs/examples/kube-module/virtual-group-td.yaml) to a component - -```yaml -apiVersion: core.oam.dev/v1beta1 -kind: Application -metadata: - name: myapp - namespace: default -spec: - components: - - name: mycomp - type: kube-worker - properties: - image: nginx:1.14.0 - traits: - - type: scaler - properties: - replicas: 2 - - type: virtualgroup - properties: - group: "my-group1" - type: "cluster" -``` - -## Verify - -Deploy the application and verify traits work. - -Check the `scaler` trait. -```shell -kubectl get manualscalertrait -``` -```console -NAME AGE -demo-podinfo-scaler-3x1sfcd34 2m -``` -```shell -kubectl get deployment mycomp -o json | jq .spec.replicas -``` -```console -2 -``` - -Check the `virtualgroup` trait. -```shell -kubectl get deployment mycomp -o json | jq .spec.template.metadata.labels -``` -```console -{ - "app.cluster.virtual.group": "my-group1", - "app.kubernetes.io/name": "myapp" -} -``` - -## Update an Application - -After the application is deployed and workloads/traits are created successfully, -you can update the application, and corresponding changes will be applied to the -workload. - -Let's make several changes on the configuration of the sample application. - -```yaml -apiVersion: core.oam.dev/v1beta1 -kind: Application -metadata: - name: myapp - namespace: default -spec: - components: - - name: mycomp - type: kube-worker - properties: - image: nginx:1.14.1 # 1.14.0 => 1.14.1 - traits: - - type: scaler - properties: - replicas: 4 # 2 => 4 - - type: virtualgroup - properties: - group: "my-group2" # my-group1 => my-group2 - type: "cluster" -``` - -Apply the new configuration and check the results after several seconds. - -> After updating, the workload instance name will be updated from `mycomp-v1` to `mycomp-v2`. - -Check the new property value. -```shell -kubectl get deployment mycomp -o json | jq '.spec.template.spec.containers[0].image' -``` -```console -"nginx:1.14.1" -``` - -Check the `scaler` trait. -```shell -kubectl get deployment mycomp -o json | jq .spec.replicas -``` -```console -4 -``` - -Check the `virtualgroup` trait. -```shell -kubectl get deployment mycomp -o json | jq .spec.template.metadata.labels -``` -```console -{ - "app.cluster.virtual.group": "my-group2", - "app.kubernetes.io/name": "myapp" -} -```