Skip to content

Instantly share code, notes, and snippets.

@singlecheeze
Last active October 21, 2022 13:14
Show Gist options
  • Save singlecheeze/d9110b676f4372b698b7b4b952350a2a to your computer and use it in GitHub Desktop.
Save singlecheeze/d9110b676f4372b698b7b4b952350a2a to your computer and use it in GitHub Desktop.
OpenShift 4.11 VM Networking

https://docs.openshift.com/container-platform/4.11/virt/virtual_machines/vm_networking/virt-using-the-default-pod-network-with-virt.html

Other helpful Links:
https://kubevirt.io/user-guide/operations/virtctl_client_tool/ https://kubevirt.io/user-guide/virtual_machines/service_objects/ https://www.opensourcerers.org/2020/11/30/first-steps-with-openshift-virtualization/

NOTE: Depending on access needed, use EITHER ClusterIP or NodePort, not BOTH as NodePort will allow for internal AND external communication; whereas ClusterIP in internal only.

image

Intra-Cluster (ClusterIP) Service:

apiVersion: v1
kind: Service
metadata:
  name: svc-postgres-clusterip
  namespace: percap
spec:
  ports:
  - protocol: TCP
    port: 5432
    targetPort: 5432
  selector:
    internalService: svc-postgres-clusterip
  type: ClusterIP

Extra-Cluster (NodePort, must be higher than 30000) Service:

apiVersion: v1
kind: Service
metadata:
  name: svc-postgres-nodeport
  namespace: percap
spec:
  ports:
  - protocol: TCP
    port: 5432
    targetPort: 5432
    nodePort: 30000
  selector:
    externalService: svc-postgres-nodeport
  type: NodePort

VM Customizations (VM MUST be fully powered off, not just rebooted, if already powered on to make services work, notice ports/port):

apiVersion: kubevirt.io/v1
kind: VirtualMachine
metadata:
  name: postgres
  namespace: percap
spec:
  running: false
  template:
    metadata:
      labels:
        internalService: svc-postgres-clusterip
  domain:
    devices:
      interfaces:
        - macAddress: '00:50:56:81:35:dd'
          masquerade: {}
          model: virtio
          name: net-0
          ports:
            - port: 5432
  networks:
    - name: net-0
      pod: {}

External connections can be made to the VM using the below (No Route is required):
Any externally facing cluster IP (Master or Worker node IPs)
API and Ingress IPs (In this case I am using 172.16.1.150, the API IP, or could use the FQDN)
image image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment