Next, we’ll create five Virtual Nodes, one for each of the microservices in our application.
A virtual node acts as a logical pointer to a k8s service.
Service Discovery / DNS name of the virtual node is defined in the serviceDiscovery.dns attribute.
Inbound traffic parameters for the virtual node are specified in the listener attribute.
Outbound traffic the virtual node forwards to should be specified in the backend attribute.
We’ll first define the virtual node colorgateway-vn. colorgateway-vn will be the entrypoint to our app.
The following JSON defines:
Copy and paste the following into your terminal to create the colorgateway virtual node:
aws appmesh create-virtual-node --mesh-name APP_MESH_DEMO --cli-input-json '{
"spec": {
"listeners": [
{
"portMapping": {
"port": 9080,
"protocol": "http"
}
}
],
"serviceDiscovery": {
"dns": {
"serviceName": "colorgateway.default.svc.cluster.local"
}
},
"backends": [
"colorteller.default.svc.cluster.local"
]
},
"virtualNodeName": "colorgateway-vn"
}'
collorteller-vn always white as its color response.
The following JSON defines:
Copy and paste the following into your terminal to create the colorteller-vn virtual node:
aws appmesh create-virtual-node --mesh-name APP_MESH_DEMO --cli-input-json '{
"spec": {
"listeners": [
{
"portMapping": {
"port": 9080,
"protocol": "http"
}
}
],
"serviceDiscovery": {
"dns": {
"serviceName": "colorteller.default.svc.cluster.local"
}
}
},
"virtualNodeName": "colorteller-vn"
}'
Similarly, colorteller-black-vn, colorteller-blue-vn, and colorteller-red-vn return the colors black, blue, and red respectively.
Copy and paste these three virtual node definitions into your terminal to create the black, blue, and red collorteller virtual nodes:
aws appmesh create-virtual-node --mesh-name APP_MESH_DEMO --cli-input-json '{
"spec": {
"listeners": [
{
"portMapping": {
"port": 9080,
"protocol": "http"
}
}
],
"serviceDiscovery": {
"dns": {
"serviceName": "colorteller-black.default.svc.cluster.local"
}
}
},
"virtualNodeName": "colorteller-black-vn"
}'
aws appmesh create-virtual-node --mesh-name APP_MESH_DEMO --cli-input-json '{
"spec": {
"listeners": [
{
"portMapping": {
"port": 9080,
"protocol": "http"
}
}
],
"serviceDiscovery": {
"dns": {
"serviceName": "colorteller-blue.default.svc.cluster.local"
}
}
},
"virtualNodeName": "colorteller-blue-vn"
}'
aws appmesh create-virtual-node --mesh-name APP_MESH_DEMO --cli-input-json '{
"spec": {
"listeners": [
{
"portMapping": {
"port": 9080,
"protocol": "http"
}
}
],
"serviceDiscovery": {
"dns": {
"serviceName": "colorteller-red.default.svc.cluster.local"
}
}
},
"virtualNodeName": "colorteller-red-vn"
}'