add end-user/labels.md (#1505)

This commit is contained in:
yangsoon
2021-04-16 13:58:42 +08:00
committed by GitHub
parent f9f2c3b119
commit 3be63bba91
7 changed files with 161 additions and 3 deletions
@@ -0,0 +1,24 @@
# Code generated by KubeVela templates. DO NOT EDIT.
apiVersion: core.oam.dev/v1beta1
kind: TraitDefinition
metadata:
annotations:
definition.oam.dev/description: "Add annotations for your Workload."
name: annotations
namespace: {{.Values.systemDefinitionNamespace}}
spec:
appliesToWorkloads:
- webservice
- worker
schematic:
cue:
template: |-
patch: {
spec: template: metadata: annotations: {
for k, v in parameter {
"\(k)": v
}
}
}
parameter: [string]: string
@@ -0,0 +1,24 @@
# Code generated by KubeVela templates. DO NOT EDIT.
apiVersion: core.oam.dev/v1beta1
kind: TraitDefinition
metadata:
annotations:
definition.oam.dev/description: "Add labels for your Workload."
name: labels
namespace: {{.Values.systemDefinitionNamespace}}
spec:
appliesToWorkloads:
- webservice
- worker
schematic:
cue:
template: |-
patch: {
spec: template: metadata: labels: {
for k, v in parameter {
"\(k)": v
}
}
}
parameter: [string]: string
+69 -3
View File
@@ -2,7 +2,73 @@
title: Labels and Annotations
---
TBD, Content Overview
We will introduce how to add labels and annotations to your Application.
1. deploy a helm chart based application.
2. Add Patch labels and annotations trait2 traits example.
## List Traits
```bash
kubectl get trait -n vela-system
NAME APPLIES-TO DESCRIPTION AGE
annotations ["webservice","worker"] Add annotations for your Workload. 24h
cpuscaler ["webservice","worker"] configure k8s HPA with CPU metrics for Deployment 24h
ingress ["webservice","worker"] Configures K8s ingress and service to enable web traffic for your service. Please use route trait in cap center for advanced usage. 24h
labels ["webservice","worker"] Add labels for your Workload. 24h
scaler ["webservice","worker"] Configures replicas for your service by patch replicas field. 24h
sidecar ["webservice","worker"] inject a sidecar container into your app 24h
```
You can use `label` and `annotations` traits to add labels and annotations for your workload.
## Apply Application
Let's use `label` and `annotations` traits in your Application.
```shell
# myapp.yaml
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: myapp
spec:
components:
- name: express-server
type: webservice
properties:
image: crccheck/hello-world
port: 8000
traits:
- type: labels
properties:
"release": "stable"
- type: annotations
properties:
"description": "web application"
```
Apply this Application.
```shell
kubectl apply -f myapp.yaml
```
Check the workload has been created successfully.
```bash
$ kubectl get deployments
NAME READY UP-TO-DATE AVAILABLE AGE
express-server 1/1 1 1 15s
```
Check the `labels` trait.
```bash
$ kubectl get deployments express-server -o jsonpath='{.spec.template.metadata.labels}'
{"app.oam.dev/component":"express-server","release": "stable"}
```
Check the `annotations` trait.
```bash
$ kubectl get deployments express-server -o jsonpath='{.spec.template.metadata.annotations}'
{"description":"web application"}
```
+8
View File
@@ -0,0 +1,8 @@
patch: {
spec: template: metadata: annotations: {
for k, v in parameter {
"\(k)": v
}
}
}
parameter: [string]: string
+8
View File
@@ -0,0 +1,8 @@
patch: {
spec: template: metadata: labels: {
for k, v in parameter {
"\(k)": v
}
}
}
parameter: [string]: string
@@ -0,0 +1,14 @@
apiVersion: core.oam.dev/v1beta1
kind: TraitDefinition
metadata:
annotations:
definition.oam.dev/description: "Add annotations for your Workload."
name: annotations
namespace: {{.Values.systemDefinitionNamespace}}
spec:
appliesToWorkloads:
- webservice
- worker
schematic:
cue:
template: |-
@@ -0,0 +1,14 @@
apiVersion: core.oam.dev/v1beta1
kind: TraitDefinition
metadata:
annotations:
definition.oam.dev/description: "Add labels for your Workload."
name: labels
namespace: {{.Values.systemDefinitionNamespace}}
spec:
appliesToWorkloads:
- webservice
- worker
schematic:
cue:
template: |-