Skip to content

Instantly share code, notes, and snippets.

@BobyMCbobs
Created October 23, 2024 21:54
Show Gist options
  • Save BobyMCbobs/8e1757799cce22b71f5c0d40e1cf2854 to your computer and use it in GitHub Desktop.
Save BobyMCbobs/8e1757799cce22b71f5c0d40e1cf2854 to your computer and use it in GitHub Desktop.
talos-on-kubevirt+cluster-api
---
apiVersion: cluster.x-k8s.io/v1beta1
kind: Cluster
metadata:
name: "${CLUSTER_NAME}"
namespace: "${NAMESPACE}"
labels:
cluster.x-k8s.io/cluster-name: ${CLUSTER_NAME}
spec:
clusterNetwork:
pods:
cidrBlocks:
- 10.243.0.0/16
services:
cidrBlocks:
- 10.95.0.0/16
infrastructureRef:
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
kind: KubevirtCluster
name: '${CLUSTER_NAME}'
namespace: "${NAMESPACE}"
controlPlaneRef:
apiVersion: controlplane.cluster.x-k8s.io/v1alpha3
kind: TalosControlPlane
name: '${CLUSTER_NAME}-control-plane'
namespace: "${NAMESPACE}"
---
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
kind: KubevirtCluster
metadata:
name: "${CLUSTER_NAME}"
namespace: "${NAMESPACE}"
labels:
cluster.x-k8s.io/cluster-name: ${CLUSTER_NAME}
spec:
controlPlaneServiceTemplate:
metadata:
labels:
cluster.x-k8s.io/cluster-name: ${CLUSTER_NAME}
spec:
type: ClusterIP
---
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
kind: KubevirtMachineTemplate
metadata:
name: "${CLUSTER_NAME}-control-plane"
namespace: "${NAMESPACE}"
labels:
cluster.x-k8s.io/cluster-name: ${CLUSTER_NAME}
spec:
template:
spec:
virtualMachineBootstrapCheck:
checkStrategy: none
virtualMachineTemplate:
metadata:
namespace: "${NAMESPACE}"
spec:
runStrategy: Always
dataVolumeTemplates:
- metadata:
name: talos
spec:
storage:
storageClassName: local-path
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
source:
http:
url: "${TALOS_FACTORY_RAW_DISK_IMAGE_URL:=https://factory.talos.dev/image/ab1024449cff00f2e27caee13298635e8fd178c6079d4de34a9370a55a54b938/v1.8.1/metal-amd64.qcow2}"
template:
spec:
architecture: "${KUBEVIRT_VM_ARCHITECTURE:=amd64}"
terminationGracePeriodSeconds: 0
networks:
- name: default
pod: {}
domain:
clock:
timer: {}
utc: {}
cpu:
cores: 2
resources:
requests:
devices.kubevirt.io/kvm: "1"
memory: 4Gi
devices:
networkInterfaceMultiqueue: true
autoattachSerialConsole: true
autoattachGraphicsDevice: true
autoattachPodInterface: false
rng: {}
interfaces:
- name: default
masquerade: {}
disks:
- disk:
bus: virtio
name: talos
evictionStrategy: External
volumes:
- dataVolume:
name: talos
name: talos
---
apiVersion: controlplane.cluster.x-k8s.io/v1alpha3
kind: TalosControlPlane
metadata:
name: "${CLUSTER_NAME}-control-plane"
namespace: sharingio
labels:
cluster.x-k8s.io/cluster-name: ${CLUSTER_NAME}
spec:
version: ${KUBERNETES_VERSION:=v1.31.1}
replicas: ${CONTROL_PLANE_MACHINE_COUNT}
infrastructureTemplate:
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
kind: KubevirtMachineTemplate
name: "${CLUSTER_NAME}-control-plane"
controlPlaneConfig:
controlplane:
generateType: controlplane
hostname:
source: MachineName
configPatches:
- op: replace
path: /machine/install
value:
disk: /dev/vda
image: ${TALOS_INSTALL_IMAGE:=factory.talos.dev/installer/ab1024449cff00f2e27caee13298635e8fd178c6079d4de34a9370a55a54b938:v1.8.1}
bootloader: true
wipe: false
# - op: add
# path: /cluster/allowSchedulingOnMasters
# value: true
# TODO add audit sink config
# https://www.talos.dev/v1.8/reference/configuration/v1alpha1/config/#Config.cluster.apiServer
# - op: add
# path: /cluster/apiServer/extraArgs
# value:
# TODO add audit sink config files
# https://www.talos.dev/v1.8/reference/configuration/v1alpha1/config/#Config.machine.files.
# - op: add
# path: /machine/files
# value:
# TODO add apisnoop
# https://www.talos.dev/v1.8/reference/configuration/v1alpha1/config/#Config.cluster
# - op: add
# path: /cluster/extraManifests
# value: []
---
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
kind: KubevirtMachineTemplate
metadata:
name: "${CLUSTER_NAME}-md-0"
namespace: "${NAMESPACE}"
labels:
cluster.x-k8s.io/cluster-name: ${CLUSTER_NAME}
spec:
template:
spec:
virtualMachineBootstrapCheck:
checkStrategy: none
virtualMachineTemplate:
metadata:
namespace: "${NAMESPACE}"
spec:
runStrategy: Always
dataVolumeTemplates:
- metadata:
name: talos
spec:
storage:
storageClassName: local-path
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
source:
http:
url: "${TALOS_FACTORY_RAW_DISK_IMAGE_URL:=https://factory.talos.dev/image/ab1024449cff00f2e27caee13298635e8fd178c6079d4de34a9370a55a54b938/v1.8.1/metal-amd64.qcow2}"
template:
spec:
architecture: "${KUBEVIRT_VM_ARCHITECTURE:=amd64}"
terminationGracePeriodSeconds: 0
networks:
- name: default
pod: {}
domain:
clock:
timer: {}
utc: {}
cpu:
cores: 2
resources:
requests:
devices.kubevirt.io/kvm: "1"
memory: 4Gi
devices:
networkInterfaceMultiqueue: true
autoattachSerialConsole: true
autoattachGraphicsDevice: true
autoattachPodInterface: false
rng: {}
interfaces:
- name: default
masquerade: {}
disks:
- disk:
bus: virtio
name: talos
evictionStrategy: External
volumes:
- dataVolume:
name: talos
name: talos
---
apiVersion: bootstrap.cluster.x-k8s.io/v1alpha3
kind: TalosConfigTemplate
metadata:
name: ${CLUSTER_NAME}-md-0
namespace: sharingio
labels:
cluster.x-k8s.io/cluster-name: ${CLUSTER_NAME}
spec:
template:
spec:
generateType: join
configPatches:
- op: replace
path: /machine/install
value:
disk: /dev/vda
image: ${TALOS_INSTALL_IMAGE:=factory.talos.dev/installer/ab1024449cff00f2e27caee13298635e8fd178c6079d4de34a9370a55a54b938:v1.8.1}
bootloader: true
wipe: false
---
apiVersion: cluster.x-k8s.io/v1beta1
kind: MachineDeployment
metadata:
name: "${CLUSTER_NAME}-md-0"
namespace: "${NAMESPACE}"
labels:
cluster.x-k8s.io/cluster-name: ${CLUSTER_NAME}
spec:
clusterName: "${CLUSTER_NAME}"
replicas: ${WORKER_MACHINE_COUNT}
selector:
matchLabels:
template:
metadata:
labels:
cluster.x-k8s.io/cluster-name: ${CLUSTER_NAME}
spec:
clusterName: "${CLUSTER_NAME}"
version: "${KUBERNETES_VERSION:=v1.31.1}"
bootstrap:
configRef:
name: "${CLUSTER_NAME}-md-0"
namespace: "${NAMESPACE}"
apiVersion: bootstrap.cluster.x-k8s.io/v1alpha3
kind: TalosConfigTemplate
infrastructureRef:
name: "${CLUSTER_NAME}-md-0"
namespace: "${NAMESPACE}"
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
kind: KubevirtMachineTemplate
---
apiVersion: v1
kind: Service
metadata:
name: "${CLUSTER_NAME}-talos"
namespace: "${NAMESPACE}"
spec:
ports:
- port: 50000
targetPort: 50000
selector:
cluster.x-k8s.io/cluster-name: "${CLUSTER_NAME}"
type: ClusterIP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment