Since our virtual machines exist within the normal OpenShift SDN, we’ll need a service to allow things to connect to it, such as Ansible.
We’ll want to have the service provide connectivity to the WinRM port on the Windows VMs, which is port 5985/tcp.
Within the factorytalk/templates
directory, add a new file named service.yaml
, and add the following contents:
{{- range .Values.virtualMachines }}
---
apiVersion: v1
kind: Service
metadata:
name: {{ .name }}-winrm
labels:
app.kubernetes.io/part-of: {{ .partOf }}
spec:
selector:
kubevirt.io/domain: {{ .name }}
ports:
- name: winrm
protocol: TCP
port: 5985
targetPort: 5985
{{- end }}
What’s a bit different in this service is the selector - instead of looking for an app label, the name of the virtual machine is used. This will result in the service attaching to the virt-helper pod of the virtual machine.
In addition, the same looping function is used, so for each VM, a service will be created with the name $(VM_NAME)-winrm
.
The fully-qualified hostname of the service will later be used by Ansible Controller to communicate to the virtual machine.
Since the HMI requires services over the network, we’ll need to expose them as well or operations such as OPC-UA, Codesys Container Runtimes, and more.
Modify your service.yaml
file to include the following between the range
function:
{{- range $.Values.virtualMachines }}
---
apiVersion: v1
kind: Service
metadata:
name: {{ .name }}-winrm
labels:
app.kubernetes.io/part-of: {{ .partOf }}
spec:
selector:
kubevirt.io/domain: {{ .name }}
ports:
- name: winrm
protocol: TCP
port: 5985
targetPort: 5985
---
apiVersion: v1
kind: Service
metadata:
name: ft-services-{{ .name }}
spec:
selector:
kubevirt.io/domain: {{ .name }}
ports:
- name: opcua
port: 4840
targetPort: 4840
protocol: TCP
- name: codesys
port: 1217
targetPort: 1217
protocol: TCP
- name: kerberos
port: 88
targetPort: 88
protocol: TCP
- name: dns
port: 53
targetPort: 53
protocol: TCP
- name: dns-udp
port: 53
targetPort: 53
protocol: UDP
- name: ssh
port: 443
targetPort: 443
protocol: TCP
- name: ssh1
port: 11740
targetPort: 11740
protocol: TCP
- name: rockwell
port: 44818
targetPort: 44818
protocol: TCP
{{- end }}
Same as above, a service will be created for every virtual machine in our list:
With the template for the services completed, be sure to commit and push the new code if using an IDE, or hit save if using the Gitea web interface.
Navigation
Pervious Exercise | Next Exercise |