Navigate to the guide-istio-intro/start
directory and run the following command to build the application locally.
Next, run the docker build
commands to build the container image for your application:
The command builds a Docker image for the system
microservice.
The -t
flag in the docker build
command allows the Docker image to be labeled (tagged) in the name[:tag]
format.
The tag for an image describes the specific image version.
If the optional [:tag]
tag is not specified, the latest
tag is created by default.
You can verify that this image was created by running the following command:
You’ll see an image called system:1.0-SNAPSHOT
listed in a table similar to the output.
REPOSITORY TAG IMAGE ID CREATED SIZE
system 1.0-SNAPSHOT 8856039f4c42 9 minutes ago 745MB
istio/proxyv2 1.20.3 7a3aaffcf645 3 weeks ago 347MB
istio/pilot 1.20.3 4974b5b22dcc 3 weeks ago 261MB
icr.io/appcafe/open-liberty kernel-slim-java11-openj9-ubi d6ef646493e1 8 days ago 729MB
To deploy the system
microservice to the Kubernetes cluster, use the following command to deploy the microservice.
You can see that your resources are created:
gateway.networking.istio.io/sys-app-gateway created
service/system-service created
deployment.apps/system-deployment-blue created
deployment.apps/system-deployment-green created
destinationrule.networking.istio.io/system-destination-rule created
View the system.yaml
file. It contains two deployments
, a service
, a gateway
, and a destination rule
. One of the deployments is labeled blue
and the second deployment is labeled green
. The service points to both of these deployments. The Istio gateway is the entry point for HTTP requests to the cluster. A destination rule is used to apply policies post-routing, in this situation it is used to define service subsets that can be specifically routed to.
View the traffic.yaml
file. It contains two virtual services. A virtual service defines how requests are routed to your applications. In the virtual services, you can configure the weight, which controls the amount of traffic going to each deployment. In this case, the weights should be 100 or 0, which corresponds to which deployment is live.
Deploy the resources defined in the traffic.yaml
file.
You can see that the virtual services have been created.
virtualservice.networking.istio.io/system-virtual-service created
virtualservice.networking.istio.io/system-test-virtual-service created
You can check that all of the deployments are available by running the following command.
The command produces a list of deployments for your microservices that is similar to the following output.
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
system-deployment-blue 1 1 1 1 1m
system-deployment-green 1 1 1 1 1m
After all the deployments are available, you will make a request to version 1 of the deployed application. As defined in the system.yaml
, file the gateway
is expecting the host to be example.com
. However, requests to example.com
won’t be routed to the appropriate IP address. To ensure that the gateway routes your requests appropriately, ensure that the Host header is set to example.com
. For instance, you can set the Host
header with the -H
option of the curl
command.
Make a request to the service by running the following curl
command.
If the curl
command is unavailable, then use Postman. Postman enables you
to make requests using a graphical interface. To make a request with Postman, enter http://localhost/system/properties
into the URL bar. Next, switch to the Headers
tab and add a header with key of Host
and value of example.com
.
Finally, click the blue Send
button to make the request.
If the curl
command is unavailable, then use Postman. Postman enables you
to make requests using a graphical interface. To make a request with Postman, enter http://localhost/system/properties
into the URL bar. Next, switch to the Headers
tab and add a header with key of Host
and value of example.com
.
Finally, click the blue Send
button to make the request.
You’ll see a header called x-app-version
along with the corresponding version.
x-app-version: 1.0-SNAPSHOT