Feat: istio addon and use case demo (#2276)

fix all error and finish readme

small change

fix CI check

add canary trait back
This commit is contained in:
wyike
2021-09-13 20:10:32 +08:00
committed by GitHub
parent b66f2995a5
commit d93d8626c0
16 changed files with 1015 additions and 0 deletions
@@ -0,0 +1,188 @@
apiVersion: v1
data:
initializer: |
apiVersion: core.oam.dev/v1beta1
kind: Initializer
metadata:
annotations:
addons.oam.dev/description: istio Controller is a Kubernetes Controller for manage
traffic.
name: istio
namespace: istio-system
spec:
appTemplate:
spec:
components:
- name: istio
properties:
chart: istio
repoType: helm
url: https://getindata.github.io/helm-charts/
version: 1.11.1
type: helm
- name: canary-rollout
properties:
apiVersion: core.oam.dev/v1beta1
kind: WorkflowStepDefinition
metadata:
name: canary-rollout
namespace: vela-system
spec:
schematic:
cue:
template: |-
import ("vela/op")
parameter: {
batchPartition: int
traffic: weightedTargets: [...{
revision: string
weight: int
}]
}
comps__: op.#Load
compNames__: [ for name, c in comps__.value {name}]
comp__: compNames__[0]
apply: op.#ApplyComponent & {
value: comps__.value[comp__]
patch: {
traits: "rollout": {
spec: rolloutPlan: batchPartition: parameter.batchPartition
}
traits: "virtualService": {
spec: http: [
{
route: [
for i, t in parameter.traffic.weightedTargets {
destination: {
host: comp__
subset: t.revision
}
weight: t.weight
}]
},
]
}
traits: "destinationRule": {
spec: subsets: [
for i, t in parameter.traffic.weightedTargets {
name: t.revision
labels: {"app.oam.dev/revision": t.revision}
},
]
}
}
}
type: raw
- name: istio-gateway
properties:
apiVersion: core.oam.dev/v1beta1
kind: TraitDefinition
metadata:
annotations:
definition.oam.dev/description: use istio to manage in-cluster traffic
name: istio-gateway
namespace: vela-system
spec:
appliesToWorkloads:
- deployments.apps
podDisruptive: true
schematic:
cue:
template: "\noutputs: gateway: {\n apiVersion: \"networking.istio.io/v1alpha3\"\n
\ kind: \"Gateway\"\n metadata: {\n name: context.name\n
\ namespace: context.namespace\n }\n spec: {\n selector:
{\n istio: parameter.gateway\n }\n servers: [{\n
\ hosts: parameter.hosts\n port: {\n name:
\"http\"\n number: 80\n protocol: \"HTTP\"\n
\ }\n }]\n }\n}\n\noutputs: virtualService: {\n apiVersion:
\"networking.istio.io/v1alpha3\"\n kind: \"VirtualService\"\n
\ metadata: {\n name: context.name\n namespace:
context.namespace\n }\n spec: {\n gateways: [context.name]\n
\ hosts: parameter.hosts\n http:[{\n match: [ for
i, u in parameter.match { uri: u} ]\n route: [{destination:
{\n host: context.name\n port: number: parameter.port\n
\ }}]\n }]\n }\n}\n\nparameter: {\n hosts: [string]\n
\ gateway: *\"ingressgateway\"|string\n match: [...#uri]\n
\ port: int\n}\n\n#uri: {\n exact?: string\n prefix?: string\n}
\n"
type: raw
- name: canary-traffic
properties:
apiVersion: core.oam.dev/v1beta1
kind: TraitDefinition
metadata:
annotations:
definition.oam.dev/description: use istio to manage traffic
name: canary-traffic
namespace: vela-system
spec:
appliesToWorkloads:
- deployments.apps
podDisruptive: true
schematic:
cue:
template: |2
outputs: virtualService: {
apiVersion: "networking.istio.io/v1alpha3"
kind: "VirtualService"
metadata: {
name: context.name
namespace: context.namespace
}
spec: {
hosts: [context.name]
}
}
outputs: destinationRule: {
apiVersion: "networking.istio.io/v1alpha3"
kind: "DestinationRule"
metadata: {
name: context.name
namespace: context.namespace
}
spec: {
host: context.name
}
}
parameter: {
port: [int]
}
type: raw
status:
rollout:
batchRollingState: ""
currentBatch: 0
lastTargetAppRevision: ""
rollingState: ""
upgradedReadyReplicas: 0
upgradedReplicas: 0
dependsOn:
- ref:
apiVersion: core.oam.dev/v1beta1
kind: Initializer
name: fluxcd
namespace: vela-system
- ref:
apiVersion: core.oam.dev/v1beta1
kind: Initializer
name: ns-istio-system
namespace: vela-system
status:
observedGeneration: 0
kind: ConfigMap
metadata:
annotations:
addons.oam.dev/description: istio Controller is a Kubernetes Controller for manage
traffic.
labels:
addons.oam.dev/type: istio
name: istio
namespace: {{.Values.systemDefinitionNamespace}}
@@ -0,0 +1,39 @@
apiVersion: v1
data:
initializer: |
apiVersion: core.oam.dev/v1beta1
kind: Initializer
metadata:
annotations:
addons.oam.dev/description: Create namespace for istio-system
name: ns-istio-system
namespace: vela-system
spec:
appTemplate:
spec:
components:
- name: istio-system
properties:
apiVersion: v1
kind: Namespace
metadata:
name: istio-system
type: raw
status:
rollout:
batchRollingState: ""
currentBatch: 0
lastTargetAppRevision: ""
rollingState: ""
upgradedReadyReplicas: 0
upgradedReplicas: 0
status:
observedGeneration: 0
kind: ConfigMap
metadata:
annotations:
addons.oam.dev/description: Create namespace for istio-system
labels:
addons.oam.dev/type: ns-istio-system
name: ns-istio-system
namespace: {{.Values.systemDefinitionNamespace}}
@@ -0,0 +1,64 @@
# Canary rollout use case
This chapter will introduce how to define a canary rollout workflow to implement [bookinfo demo](https://istio.io/latest/docs/examples/bookinfo/?ie=utf-8&hl=en&docs-search=Canary) by leverage [istio](https://istio.io/latest/)
## Prerequisite
enable istio addon in you cluster
```shell
vela addon enable istio
```
enable label istio injection in `default namespace`
```shell
kubectl label namespace default istio-injection=enabled
```
## First deployment
```shell
kubectl apply -f first-deploy.yaml
```
Wait a few minutes all pods have been ready. Use kubectl port-forward map gateway's service port to localhost.
```shell
kubectl port-forward service/istio-ingressgateway -n istio-system 19082:80
```
Request `127.0.0.1:19082` in your browser will see webpage like this.
![pic-v1](../../resources/canary-pic-v2.jpg)
## Canary Rollout
Update application to define a canary rollout workflow. This workflow will suspend after only upgrade one batch pods of `reviews` component and shift 10% traffic to new revision. It's give user some time to manual-check.
```shell
kubectl apply -f rollout-v2.yaml
```
Wait a few minutes new revision pods ready. Request `127.0.0.1:19082` in your browser again several times. Will see almost 90% chance see previous the webpage and 10% chance see the new webpage whose reviews will display red starts like this.
![pic-v2](../../resources/canary-pic-v3.jpg)
### Rollout rest batches and traffic
resume workflow to continue rollout rest replicas and shift all traffic to new revision.
```shell
vela workflow reumse book-info
```
By request again. You will always see the new webpage
### Cancel rollout workflow and revert.
If you find some problems after manual-check and want to revert to previous revision. You can cancel the rollout workflow and revert.
```shell
kubectl apply -f revert-in-middle.yaml
```
By request again. You will always see the old webpage
@@ -0,0 +1,83 @@
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: book-info
namespace: default
spec:
components:
- name: reviews
type: webservice
properties:
image: docker.io/istio/examples-bookinfo-reviews-v2:1.16.2
port: 9080
volumes:
- name: wlp-output
type: emptyDir
mountPath: /opt/ibm/wlp/output
- name: tmp
type: emptyDir
mountPath: /tmp
traits:
- type: expose
properties:
port:
- 9080
- type: rollout
properties:
targetSize: 2
# This means to rollout two more replicas in two batches.
rolloutBatches:
- replicas: 2
- name: productpage
type: webservice
properties:
image: docker.io/istio/examples-bookinfo-productpage-v1:1.16.2
port: 9080
traits:
- type: expose
properties:
port:
- 9080
- type: istio-gateway
properties:
hosts:
- "*"
gateway: ingressgateway
match:
- exact: /productpage
- prefix: /static
- exact: /login
- prefix: /api/v1/products
port: 9080
- name: ratings
type: webservice
properties:
image: docker.io/istio/examples-bookinfo-ratings-v1:1.16.2
port: 9080
traits:
- type: expose
properties:
port:
- 9080
- name: details
type: webservice
properties:
image: docker.io/istio/examples-bookinfo-details-v1:1.16.2
port: 9080
traits:
- type: expose
properties:
port:
- 9080
@@ -0,0 +1,85 @@
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: book-info
namespace: default
spec:
components:
- name: reviews
type: webservice
properties:
image: docker.io/istio/examples-bookinfo-reviews-v3:1.16.2
port: 9080
volumes:
- name: wlp-output
type: emptyDir
mountPath: /opt/ibm/wlp/output
- name: tmp
type: emptyDir
mountPath: /tmp
traits:
- type: expose
properties:
port:
- 9080
- type: rollout
properties:
targetRevision: reviews-v1
batchPartition: 1
targetSize: 2
# This means to rollout two more replicas in two batches.
rolloutBatches:
- replicas: 2
- name: productpage
type: webservice
properties:
image: docker.io/istio/examples-bookinfo-productpage-v1:1.16.2
port: 9080
traits:
- type: expose
properties:
port:
- 9080
- type: istio-gateway
properties:
hosts:
- "*"
gateway: ingressgateway
match:
- exact: /productpage
- prefix: /static
- exact: /login
- prefix: /api/v1/products
port: 9080
- name: ratings
type: webservice
properties:
image: docker.io/istio/examples-bookinfo-ratings-v1:1.16.2
port: 9080
traits:
- type: expose
properties:
port:
- 9080
- name: details
type: webservice
properties:
image: docker.io/istio/examples-bookinfo-details-v1:1.16.2
port: 9080
traits:
- type: expose
properties:
port:
- 9080
@@ -0,0 +1,116 @@
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: book-info
namespace: default
spec:
components:
- name: reviews
type: webservice
properties:
image: docker.io/istio/examples-bookinfo-reviews-v3:1.16.2
port: 9080
volumes:
- name: wlp-output
type: emptyDir
mountPath: /opt/ibm/wlp/output
- name: tmp
type: emptyDir
mountPath: /tmp
traits:
- type: expose
properties:
port:
- 9080
- type: rollout
properties:
targetSize: 2
# This means to rollout two more replicas in two batches.
rolloutBatches:
- replicas: 1
- replicas: 1
- type: canary-traffic
properties:
port: 9080
- name: productpage
type: webservice
properties:
image: docker.io/istio/examples-bookinfo-productpage-v1:1.16.2
port: 9080
traits:
- type: expose
properties:
port:
- 9080
- type: istio-gateway
properties:
hosts:
- "*"
gateway: ingressgateway
match:
- exact: /productpage
- prefix: /static
- exact: /login
- prefix: /api/v1/products
port: 9080
- name: ratings
type: webservice
properties:
image: docker.io/istio/examples-bookinfo-ratings-v1:1.16.2
port: 9080
traits:
- type: expose
properties:
port:
- 9080
- name: details
type: webservice
properties:
image: docker.io/istio/examples-bookinfo-details-v1:1.16.2
port: 9080
traits:
- type: expose
properties:
port:
- 9080
workflow:
steps:
- name: rollout-1st-batch
type: canary-rollout
properties:
# just upgrade first batch of component
batchPartition: 0
traffic:
weightedTargets:
- revision: reviews-v1
weight: 90 # 90% shift to new version
- revision: reviews-v2
weight: 10 # 10% shift to new version
# give user time to verify part of traffic shifting to newRevision
- name: manual-approval
type: suspend
- name: rollout-rest
type: canary-rollout
properties:
# upgrade all batches of component
batchPartition: 1
traffic:
weightedTargets:
- revision: reviews-v2
weight: 100 # 100% shift to new version
Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

+176
View File
@@ -0,0 +1,176 @@
apiVersion: core.oam.dev/v1beta1
kind: Initializer
metadata:
annotations:
addons.oam.dev/description: istio Controller is a Kubernetes Controller for manage
traffic.
name: istio
namespace: istio-system
spec:
appTemplate:
spec:
components:
- name: istio
properties:
chart: istio
repoType: helm
url: https://getindata.github.io/helm-charts/
version: 1.11.1
type: helm
- name: canary-rollout
properties:
apiVersion: core.oam.dev/v1beta1
kind: WorkflowStepDefinition
metadata:
name: canary-rollout
namespace: vela-system
spec:
schematic:
cue:
template: |-
import ("vela/op")
parameter: {
batchPartition: int
traffic: weightedTargets: [...{
revision: string
weight: int
}]
}
comps__: op.#Load
compNames__: [ for name, c in comps__.value {name}]
comp__: compNames__[0]
apply: op.#ApplyComponent & {
value: comps__.value[comp__]
patch: {
traits: "rollout": {
spec: rolloutPlan: batchPartition: parameter.batchPartition
}
traits: "virtualService": {
spec: http: [
{
route: [
for i, t in parameter.traffic.weightedTargets {
destination: {
host: comp__
subset: t.revision
}
weight: t.weight
}]
},
]
}
traits: "destinationRule": {
spec: subsets: [
for i, t in parameter.traffic.weightedTargets {
name: t.revision
labels: {"app.oam.dev/revision": t.revision}
},
]
}
}
}
type: raw
- name: istio-gateway
properties:
apiVersion: core.oam.dev/v1beta1
kind: TraitDefinition
metadata:
annotations:
definition.oam.dev/description: use istio to manage in-cluster traffic
name: istio-gateway
namespace: vela-system
spec:
appliesToWorkloads:
- deployments.apps
podDisruptive: true
schematic:
cue:
template: "\noutputs: gateway: {\n apiVersion: \"networking.istio.io/v1alpha3\"\n
\ kind: \"Gateway\"\n metadata: {\n name: context.name\n
\ namespace: context.namespace\n }\n spec: {\n selector:
{\n istio: parameter.gateway\n }\n servers: [{\n
\ hosts: parameter.hosts\n port: {\n name:
\"http\"\n number: 80\n protocol: \"HTTP\"\n
\ }\n }]\n }\n}\n\noutputs: virtualService: {\n apiVersion:
\"networking.istio.io/v1alpha3\"\n kind: \"VirtualService\"\n
\ metadata: {\n name: context.name\n namespace:
context.namespace\n }\n spec: {\n gateways: [context.name]\n
\ hosts: parameter.hosts\n http:[{\n match: [ for
i, u in parameter.match { uri: u} ]\n route: [{destination:
{\n host: context.name\n port: number: parameter.port\n
\ }}]\n }]\n }\n}\n\nparameter: {\n hosts: [string]\n
\ gateway: *\"ingressgateway\"|string\n match: [...#uri]\n
\ port: int\n}\n\n#uri: {\n exact?: string\n prefix?: string\n}
\n"
type: raw
- name: canary-traffic
properties:
apiVersion: core.oam.dev/v1beta1
kind: TraitDefinition
metadata:
annotations:
definition.oam.dev/description: use istio to manage traffic
name: canary-traffic
namespace: vela-system
spec:
appliesToWorkloads:
- deployments.apps
podDisruptive: true
schematic:
cue:
template: |2
outputs: virtualService: {
apiVersion: "networking.istio.io/v1alpha3"
kind: "VirtualService"
metadata: {
name: context.name
namespace: context.namespace
}
spec: {
hosts: [context.name]
}
}
outputs: destinationRule: {
apiVersion: "networking.istio.io/v1alpha3"
kind: "DestinationRule"
metadata: {
name: context.name
namespace: context.namespace
}
spec: {
host: context.name
}
}
parameter: {
port: [int]
}
type: raw
status:
rollout:
batchRollingState: ""
currentBatch: 0
lastTargetAppRevision: ""
rollingState: ""
upgradedReadyReplicas: 0
upgradedReplicas: 0
dependsOn:
- ref:
apiVersion: core.oam.dev/v1beta1
kind: Initializer
name: fluxcd
namespace: vela-system
- ref:
apiVersion: core.oam.dev/v1beta1
kind: Initializer
name: ns-istio-system
namespace: vela-system
status:
observedGeneration: 0
@@ -0,0 +1,28 @@
apiVersion: core.oam.dev/v1beta1
kind: Initializer
metadata:
annotations:
addons.oam.dev/description: Create namespace for istio-system
name: ns-istio-system
namespace: vela-system
spec:
appTemplate:
spec:
components:
- name: istio-system
properties:
apiVersion: v1
kind: Namespace
metadata:
name: istio-system
type: raw
status:
rollout:
batchRollingState: ""
currentBatch: 0
lastTargetAppRevision: ""
rollingState: ""
upgradedReadyReplicas: 0
upgradedReplicas: 0
status:
observedGeneration: 0
@@ -0,0 +1,62 @@
apiVersion: core.oam.dev/v1beta1
kind: WorkflowStepDefinition
metadata:
name: canary-rollout
namespace: vela-system
spec:
schematic:
cue:
template: |-
import ("vela/op")
parameter: {
batchPartition: int
traffic: weightedTargets: [...{
revision: string
weight: int
}]
}
comps__: op.#Load
compNames__: [ for name, c in comps__.value {name}]
comp__: compNames__[0]
apply: op.#ApplyComponent & {
value: comps__.value[comp__]
patch: {
traits: "rollout": {
spec: rolloutPlan: batchPartition: parameter.batchPartition
}
traits: "virtualService": {
spec: http: [
{
route: [
for i, t in parameter.traffic.weightedTargets {
destination: {
host: comp__
subset: t.revision
}
weight: t.weight
}]
},
]
}
traits: "destinationRule": {
spec: subsets: [
for i, t in parameter.traffic.weightedTargets {
name: t.revision
labels: {"app.oam.dev/revision": t.revision}
},
]
}
}
}
@@ -0,0 +1,70 @@
# Code generated by KubeVela templates. DO NOT EDIT. Please edit the original cue file.
# Definition source cue file: vela-templates/definitions/internal/volumes.cue
apiVersion: core.oam.dev/v1beta1
kind: TraitDefinition
metadata:
annotations:
definition.oam.dev/description: use istio to manage in-cluster traffic
name: istio-gateway
namespace: vela-system
spec:
appliesToWorkloads:
- deployments.apps
podDisruptive: true
schematic:
cue:
template: |
outputs: gateway: {
apiVersion: "networking.istio.io/v1alpha3"
kind: "Gateway"
metadata: {
name: context.name
namespace: context.namespace
}
spec: {
selector: {
istio: parameter.gateway
}
servers: [{
hosts: parameter.hosts
port: {
name: "http"
number: 80
protocol: "HTTP"
}
}]
}
}
outputs: virtualService: {
apiVersion: "networking.istio.io/v1alpha3"
kind: "VirtualService"
metadata: {
name: context.name
namespace: context.namespace
}
spec: {
gateways: [context.name]
hosts: parameter.hosts
http:[{
match: [ for i, u in parameter.match { uri: u} ]
route: [{destination: {
host: context.name
port: number: parameter.port
}}]
}]
}
}
parameter: {
hosts: [string]
gateway: *"ingressgateway"|string
match: [...#uri]
port: int
}
#uri: {
exact?: string
prefix?: string
}
@@ -0,0 +1,45 @@
# Code generated by KubeVela templates. DO NOT EDIT. Please edit the original cue file.
# Definition source cue file: vela-templates/definitions/internal/volumes.cue
apiVersion: core.oam.dev/v1beta1
kind: TraitDefinition
metadata:
annotations:
definition.oam.dev/description: use istio to manage traffic
name: canary-traffic
namespace: vela-system
spec:
appliesToWorkloads:
- deployments.apps
podDisruptive: true
schematic:
cue:
template: |
outputs: virtualService: {
apiVersion: "networking.istio.io/v1alpha3"
kind: "VirtualService"
metadata: {
name: context.name
namespace: context.namespace
}
spec: {
hosts: [context.name]
}
}
outputs: destinationRule: {
apiVersion: "networking.istio.io/v1alpha3"
kind: "DestinationRule"
metadata: {
name: context.name
namespace: context.namespace
}
spec: {
host: context.name
}
}
parameter: {
port: [int]
}
+39
View File
@@ -0,0 +1,39 @@
apiVersion: core.oam.dev/v1beta1
kind: Initializer
metadata:
annotations:
addons.oam.dev/description: "istio Controller is a Kubernetes Controller for manage traffic."
name: istio
namespace: istio-system
spec:
dependsOn:
- ref:
apiVersion: core.oam.dev/v1beta1
kind: Initializer
name: fluxcd
namespace: vela-system
- ref:
apiVersion: core.oam.dev/v1beta1
kind: Initializer
name: ns-istio-system
namespace: vela-system
appTemplate:
spec:
components:
- name: istio
type: helm
properties:
repoType: helm
url: https://getindata.github.io/helm-charts/
chart: istio
version: 1.11.1
{{ range .ResourceFiles }}
- name: {{ .Name }}
type: raw
properties:
{{ .Content | indent 12 }} {{ end }}
{{ range .DefinitionFiles }}
- name: {{ .Name }}
type: raw
properties:
{{ .Content | indent 12 }} {{ end }}
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: istio-system
@@ -0,0 +1,16 @@
apiVersion: core.oam.dev/v1beta1
kind: Initializer
metadata:
annotations:
addons.oam.dev/description: "Create namespace for istio-system"
name: ns-istio-system
namespace: vela-system
spec:
appTemplate:
spec:
components:
{{ range .ResourceFiles }}
- name: {{ .Name }}
type: raw
properties:
{{ .Content | indent 12 }} {{ end }}