|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * virt/virtual_machines/vm_networking/virt-connecting-vm-to-service-mesh.adoc |
| 4 | + |
| 5 | +[id="virt-adding-vm-to-service-mesh_{context}"] |
| 6 | += Configuring a virtual machine for the service mesh |
| 7 | + |
| 8 | +To add a virtual machine (VM) workload to a service mesh, enable automatic sidecar injection in the VM configuration file by setting the `sidecar.istio.io/inject` annotation to `true`. Then expose your VM as a service to view your application in the mesh. |
| 9 | + |
| 10 | + |
| 11 | +.Procedure |
| 12 | + |
| 13 | +. Edit the VM configuration file to add the `sidecar.istio.io/inject: "true"` annotation. |
| 14 | ++ |
| 15 | +.Example configuration file |
| 16 | +[source,yaml] |
| 17 | +---- |
| 18 | + apiVersion: kubevirt.io/v1 |
| 19 | + kind: VirtualMachine |
| 20 | + metadata: |
| 21 | + labels: |
| 22 | + kubevirt.io/vm: vm-istio |
| 23 | + name: vm-istio |
| 24 | + spec: |
| 25 | + runStrategy: Always |
| 26 | + template: |
| 27 | + metadata: |
| 28 | + labels: |
| 29 | + kubevirt.io/vm: vm-istio |
| 30 | + app: vm-istio <1> |
| 31 | + annotations: |
| 32 | + sidecar.istio.io/inject: "true" <2> |
| 33 | + spec: |
| 34 | + domain: |
| 35 | + devices: |
| 36 | + interfaces: |
| 37 | + - name: default |
| 38 | + masquerade: {} <3> |
| 39 | + disks: |
| 40 | + - disk: |
| 41 | + bus: virtio |
| 42 | + name: containerdisk |
| 43 | + - disk: |
| 44 | + bus: virtio |
| 45 | + name: cloudinitdisk |
| 46 | + resources: |
| 47 | + requests: |
| 48 | + memory: 1024M |
| 49 | + networks: |
| 50 | + - name: default |
| 51 | + pod: {} |
| 52 | + terminationGracePeriodSeconds: 0 |
| 53 | + volumes: |
| 54 | + - containerDisk: |
| 55 | + image: registry:5000/kubevirt/fedora-cloud-container-disk-demo:devel |
| 56 | + name: containerdisk |
| 57 | +---- |
| 58 | +<1> The key/value pair (label) that must be matched to the service selector attribute. |
| 59 | +<2> The annotation to enable automatic sidecar injection. |
| 60 | +<3> The binding method (masquerade mode) for use with the default pod network. |
| 61 | ++ |
| 62 | +[NOTE] |
| 63 | +==== |
| 64 | +To avoid port conflicts with sidecars, do not use ports used by Istio proxy for user workloads. |
| 65 | +==== |
| 66 | + |
| 67 | +. Apply the VM configuration: |
| 68 | ++ |
| 69 | +[source,terminal] |
| 70 | +---- |
| 71 | +$ oc apply -f <vm_name>.yaml <1> |
| 72 | +---- |
| 73 | +<1> The name of the virtual machine YAML file. |
| 74 | + |
| 75 | + |
| 76 | +. Create a `Service` object to expose your VM to the service mesh. |
| 77 | ++ |
| 78 | +[source,yaml] |
| 79 | +---- |
| 80 | + apiVersion: v1 |
| 81 | + kind: Service |
| 82 | + metadata: |
| 83 | + name: vm-istio |
| 84 | + spec: |
| 85 | + selector: |
| 86 | + app: vm-istio <1> |
| 87 | + ports: |
| 88 | + - port: 8080 |
| 89 | + name: http |
| 90 | + protocol: TCP |
| 91 | +---- |
| 92 | +<1> The service selector that determines the set of pods targeted by a service. This attribute corresponds to the `spec.metadata.labels` field in the VM configuration file. In the above example, the `Service` object named `vm-istio` targets TCP port 8080 on any pod with the label `app=vm-istio`. |
| 93 | + |
| 94 | +. Create the service: |
| 95 | ++ |
| 96 | +[source,terminal] |
| 97 | +---- |
| 98 | +$ oc create -f <service_name>.yaml <1> |
| 99 | +---- |
| 100 | +<1> The name of the service YAML file. |
0 commit comments