diff --git a/packages/apps/virtual-machine/README.md b/packages/apps/virtual-machine/README.md index b1d5c6ec..37367eaf 100644 --- a/packages/apps/virtual-machine/README.md +++ b/packages/apps/virtual-machine/README.md @@ -6,19 +6,53 @@ A Virtual Machine (VM) simulates computer hardware, enabling various operating s The virtual machine is managed and hosted through KubeVirt, allowing you to harness the benefits of virtualization within your Kubernetes ecosystem. -- Docs: https://kubevirt.io/user-guide/ -- GitHub: https://github.com/kubevirt/kubevirt +- Docs: [KubeVirt User Guide](https://kubevirt.io/user-guide/) +- GitHub: [KubeVirt Repository](https://github.com/kubevirt/kubevirt) ## Parameters ### Common parameters -| Name | Description | Value | -| ------------------ | ------------------------------------------------------------------------------------------------- | -------- | -| `external` | Enable external access from outside the cluster | `false` | -| `running` | Determines if the virtual machine should be running | `true` | -| `password` | The default password for the virtual machine | `hackme` | -| `image` | The base image for the virtual machine. Allowed values: `ubuntu`, `cirros`, `alpine` and `fedora` | `ubuntu` | -| `disk` | The size of the disk allocated for the virtual machine | `5Gi` | -| `resources.cpu` | The number of CPU cores allocated to the virtual machine | `1` | -| `resources.memory` | The amount of memory allocated to the virtual machine | `1024M` | +| Name | Description | Value | +| ------------------ | ------------------------------------------------------------------------------------------------- | ----------------------------------- | +| `external` | Enable external access from outside the cluster | `false` | +| `running` | Determines if the virtual machine should be running | `true` | +| `image` | The base image for the virtual machine. Allowed values: `ubuntu`, `cirros`, `alpine` and `fedora` | `ubuntu` | +| `resources.cpu` | The number of CPU cores allocated to the virtual machine | `1` | +| `resources.memory` | The amount of memory allocated to the virtual machine | `1024M` | +| `resources.disk` | The size of the disk allocated for the virtual machine | `5Gi` | +| `sshPwauth` | Enable password authentication for SSH. If set to `true`, users can log in using a password | `true` | +| `disableRoot` | Disable root login via SSH. If set to `true`, root login will be disabled | `true` | +| `password` | The default password for the virtual machine | `hackme` | +| `chpasswdExpire` | Set whether the password should expire | `false` | +| `sshKeys` | List of SSH public keys for authentication. Can be a single key or a list of keys | `["ssh-rsa ...","ssh-ed25519 ..."]` | + +You can customize the exposed ports by specifying them under `service.ports` in the `values.yaml` file. + +## Example `values.yaml` + +```yaml +external: false +running: true +image: ubuntu +resources: + cpu: 1 + memory: 1024M + disk: 5Gi +sshPwauth: true +disableRoot: true +password: hackme +chpasswdExpire: false +sshKeys: + - YOUR_SSH_PUB_KEY_HERE + - ANOTHER_SSH_PUB_KEY_HERE + +service: + ports: + - name: http + port: 80 + targetPort: 80 + - name: https + port: 443 + targetPort: 443 +``` diff --git a/packages/apps/virtual-machine/templates/service.yaml b/packages/apps/virtual-machine/templates/service.yaml index c69ec34b..df656fa2 100644 --- a/packages/apps/virtual-machine/templates/service.yaml +++ b/packages/apps/virtual-machine/templates/service.yaml @@ -15,13 +15,14 @@ spec: selector: {{- include "virtual-machine.labels" . | nindent 4 }} ports: - - name: ssh - port: 22 - targetPort: 22 - - name: http - port: 80 - targetPort: 80 - - name: https - port: 443 - targetPort: 443 + - name: ssh + port: 22 + targetPort: 22 + {{- if .Values.service.ports }} + {{- range .Values.service.ports }} + - name: {{ .name }} + port: {{ .port }} + targetPort: {{ .targetPort }} + {{- end }} + {{- end }} {{- end }} diff --git a/packages/apps/virtual-machine/templates/vm.yaml b/packages/apps/virtual-machine/templates/vm.yaml index 05885500..1aefb757 100644 --- a/packages/apps/virtual-machine/templates/vm.yaml +++ b/packages/apps/virtual-machine/templates/vm.yaml @@ -1,11 +1,11 @@ -apiVersion: kubevirt.io/v1alpha3 +apiVersion: kubevirt.io/v1 kind: VirtualMachine metadata: name: {{ include "virtual-machine.fullname" . }} labels: {{- include "virtual-machine.labels" . | nindent 4 }} spec: - running: true + running: {{ .Values.running | default "true" }} dataVolumeTemplates: - metadata: name: {{ include "virtual-machine.fullname" . }} @@ -15,20 +15,19 @@ spec: - ReadWriteOnce resources: requests: - storage: {{ .Values.disk | quote }} + storage: {{ .Values.resources.disk | quote }} storageClassName: replicated source: http: {{- if eq .Values.image "cirros" }} url: https://download.cirros-cloud.net/0.6.2/cirros-0.6.2-x86_64-disk.img {{- else if eq .Values.image "ubuntu" }} - url: https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img + url: https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img {{- else if eq .Values.image "fedora" }} - url: https://mirror.karneval.cz/pub/linux/fedora/linux/releases/39/Cloud/x86_64/images/Fedora-Cloud-Base-39-1.5.x86_64.qcow2 + url: https://download.fedoraproject.org/pub/fedora/linux/releases/40/Cloud/x86_64/images/Fedora-Cloud-Base-Generic.x86_64-40-1.14.qcow2 {{- else if eq .Values.image "alpine" }} - url: https://dl-cdn.alpinelinux.org/alpine/v3.19/releases/x86_64/alpine-virt-3.19.1-x86_64.iso + url: https://dl-cdn.alpinelinux.org/alpine/v3.20/releases/x86_64/alpine-virt-3.20.2-x86_64.iso {{- end }} - template: metadata: annotations: @@ -60,6 +59,18 @@ spec: - cloudInitNoCloud: userData: |- #cloud-config + ssh_pwauth: {{ if .Values.sshPwauth | default false }}True{{ else }}False{{ end }} + disable_root: {{ if .Values.disableRoot | default false }}True{{ else }}False{{ end }} password: {{ .Values.password }} - chpasswd: { expire: False } + chpasswd: { expire: {{ if .Values.chpasswdExpire | default false }}True{{ else }}False{{ end }} } + ssh_authorized_keys: + {{- if .Values.sshKeys }} + {{- $keys := .Values.sshKeys }} + {{- if not (kindIs "slice" $keys) }} + {{- $keys = list $keys }} + {{- end }} + {{- range $keys }} + - {{ . }} + {{- end }} + {{- end }} name: cloudinitdisk diff --git a/packages/apps/virtual-machine/values.schema.json b/packages/apps/virtual-machine/values.schema.json index eda05ecb..43a06b32 100644 --- a/packages/apps/virtual-machine/values.schema.json +++ b/packages/apps/virtual-machine/values.schema.json @@ -12,11 +12,6 @@ "description": "Determines if the virtual machine should be running", "default": true }, - "password": { - "type": "string", - "description": "The default password for the virtual machine", - "default": "hackme" - }, "image": { "type": "string", "description": "The base image for the virtual machine. Allowed values: `ubuntu`, `cirros`, `alpine` and `fedora`", @@ -28,11 +23,6 @@ "fedora" ] }, - "disk": { - "type": "string", - "description": "The size of the disk allocated for the virtual machine", - "default": "5Gi" - }, "resources": { "type": "object", "properties": { @@ -46,8 +36,44 @@ "description": "The amount of memory allocated to the virtual machine", "default": "1024M", "x-display": "slider" + }, + "disk": { + "type": "string", + "description": "The size of the disk allocated for the virtual machine", + "default": "5Gi" } } + }, + "sshPwauth": { + "type": "boolean", + "description": "Enable password authentication for SSH. If set to `true`, users can log in using a password", + "default": true + }, + "disableRoot": { + "type": "boolean", + "description": "Disable root login via SSH. If set to `true`, root login will be disabled", + "default": true + }, + "password": { + "type": "string", + "description": "The default password for the virtual machine", + "default": "hackme" + }, + "chpasswdExpire": { + "type": "boolean", + "description": "Set whether the password should expire", + "default": false + }, + "sshKeys": { + "type": "array", + "description": "List of SSH public keys for authentication. Can be a single key or a list of keys", + "default": [ + "ssh-rsa ...", + "ssh-ed25519 ..." + ], + "items": { + "type": "string" + } } } } diff --git a/packages/apps/virtual-machine/values.yaml b/packages/apps/virtual-machine/values.yaml index 19b37d64..0c7c4407 100644 --- a/packages/apps/virtual-machine/values.yaml +++ b/packages/apps/virtual-machine/values.yaml @@ -2,17 +2,27 @@ ## @param external Enable external access from outside the cluster ## @param running Determines if the virtual machine should be running -## @param password The default password for the virtual machine ## @param image The base image for the virtual machine. Allowed values: `ubuntu`, `cirros`, `alpine` and `fedora` -## @param disk The size of the disk allocated for the virtual machine ## @param resources.cpu The number of CPU cores allocated to the virtual machine ## @param resources.memory The amount of memory allocated to the virtual machine +## @param resources.disk The size of the disk allocated for the virtual machine +## @param sshPwauth Enable password authentication for SSH. If set to `true`, users can log in using a password +## @param disableRoot Disable root login via SSH. If set to `true`, root login will be disabled +## @param password The default password for the virtual machine +## @param chpasswdExpire Set whether the password should expire +## @param sshKeys List of SSH public keys for authentication. Can be a single key or a list of keys external: false running: true -password: hackme image: ubuntu -disk: 5Gi resources: cpu: 1 memory: 1024M + disk: 5Gi +sshPwauth: true +disableRoot: true +password: hackme +chpasswdExpire: false +sshKeys: + - ssh-rsa ... + - ssh-ed25519 ...