Add LXC container and TurnKey template support

This commit is contained in:
Alphaeus Mote
2025-05-11 09:27:20 -04:00
parent 64c49b462d
commit 8f84140337
20 changed files with 3178 additions and 4 deletions
@@ -0,0 +1,118 @@
# Get-ProxmoxContainer
## SYNOPSIS
Gets Proxmox LXC containers.
## SYNTAX
```powershell
Get-ProxmoxContainer [[-CTID] <Int32>] [[-Node] <String>] [[-Name] <String>] [<CommonParameters>]
```
## DESCRIPTION
Gets Proxmox LXC containers from a Proxmox server.
If no parameters are specified, all containers are returned.
If a CTID is specified, only that container is returned.
If a node is specified, only containers on that node are returned.
If a name is specified, only containers with that name are returned (supports wildcards and regex).
## EXAMPLES
### Example 1: Get all containers
```powershell
Get-ProxmoxContainer
```
Gets all containers from the Proxmox server.
### Example 2: Get a specific container
```powershell
Get-ProxmoxContainer -CTID 100
```
Gets the container with CTID 100.
### Example 3: Get all containers on a specific node
```powershell
Get-ProxmoxContainer -Node "pve1"
```
Gets all containers on node pve1.
### Example 4: Get containers by name using wildcards
```powershell
Get-ProxmoxContainer -Name "web*"
```
Gets all containers with names starting with "web" (wildcard).
### Example 5: Get containers by name using regex
```powershell
Get-ProxmoxContainer -Name "^web\d+$"
```
Gets all containers with names matching the regex pattern "^web\d+$".
## PARAMETERS
### -CTID
The container ID.
```yaml
Type: Int32
Parameter Sets: (All)
Aliases:
Required: False
Position: 0
Default value: None
Accept pipeline input: True (ByValue, ByPropertyName)
Accept wildcard characters: False
```
### -Node
The node name.
```yaml
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: 1
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```
### -Name
The container name (supports wildcards and regex).
```yaml
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: 2
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: True
```
### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
## INPUTS
### System.Int32
### System.String
## OUTPUTS
### PSProxmox.Models.ProxmoxContainer
## NOTES
## RELATED LINKS
@@ -0,0 +1,116 @@
# Get-ProxmoxTurnKeyTemplate
## SYNOPSIS
Gets TurnKey Linux templates for Proxmox LXC containers.
## SYNTAX
```powershell
Get-ProxmoxTurnKeyTemplate [[-Node] <String>] [[-Name] <String>] [-IncludeDownloaded] [<CommonParameters>]
```
## DESCRIPTION
Gets TurnKey Linux templates for Proxmox LXC containers from a Proxmox server.
If no parameters are specified, all templates are returned.
If a node is specified, only templates available on that node are returned.
If a name is specified, only templates with that name are returned (supports wildcards and regex).
## EXAMPLES
### Example 1: Get all TurnKey templates
```powershell
Get-ProxmoxTurnKeyTemplate
```
Gets all TurnKey Linux templates from the Proxmox server.
### Example 2: Get all TurnKey templates on a specific node
```powershell
Get-ProxmoxTurnKeyTemplate -Node "pve1"
```
Gets all TurnKey Linux templates available on node pve1.
### Example 3: Get TurnKey templates by name using wildcards
```powershell
Get-ProxmoxTurnKeyTemplate -Name "wordpress*"
```
Gets all TurnKey Linux templates with names starting with "wordpress" (wildcard).
### Example 4: Get TurnKey templates by name using regex
```powershell
Get-ProxmoxTurnKeyTemplate -Name "^wordpress\d+$"
```
Gets all TurnKey Linux templates with names matching the regex pattern "^wordpress\d+$".
### Example 5: Include downloaded templates
```powershell
Get-ProxmoxTurnKeyTemplate -IncludeDownloaded
```
Gets all TurnKey Linux templates, including those that have already been downloaded.
## PARAMETERS
### -Node
The node name.
```yaml
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: 0
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```
### -Name
The template name (supports wildcards and regex).
```yaml
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: 1
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: True
```
### -IncludeDownloaded
Whether to include downloaded templates.
```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
## INPUTS
### System.String
## OUTPUTS
### PSProxmox.Models.ProxmoxTurnKeyTemplate
## NOTES
## RELATED LINKS
@@ -0,0 +1,303 @@
# New-ProxmoxContainer
## SYNOPSIS
Creates a new Proxmox LXC container.
## SYNTAX
```powershell
New-ProxmoxContainer -Node <String> [-Builder <ProxmoxContainerBuilder>] [-CTID <Int32>] [-Name <String>]
[-OSTemplate <String>] [-Storage <String>] [-Memory <Int32>] [-Swap <Int32>] [-Cores <Int32>]
[-DiskSize <Int32>] [-Unprivileged] [-Password <SecureString>] [-SSHKey <String>] [-Description <String>]
[-StartOnBoot] [-Start] [<CommonParameters>]
```
## DESCRIPTION
Creates a new Proxmox LXC container on a Proxmox server.
## EXAMPLES
### Example 1: Create a new container
```powershell
New-ProxmoxContainer -Node "pve1" -Name "web-container" -OSTemplate "local:vztmpl/ubuntu-20.04-standard_20.04-1_amd64.tar.gz" -Storage "local-lvm" -Memory 512 -Swap 512 -Cores 1 -DiskSize 8
```
Creates a new LXC container on node pve1.
### Example 2: Create a new container using a builder
```powershell
$builder = New-ProxmoxContainerBuilder -Name "web-container"
$builder.WithOSTemplate("local:vztmpl/ubuntu-20.04-standard_20.04-1_amd64.tar.gz")
.WithStorage("local-lvm")
.WithMemory(512)
.WithSwap(512)
.WithCores(1)
.WithDiskSize(8)
.WithUnprivileged($true)
.WithStartOnBoot($true)
.WithStart($true)
New-ProxmoxContainer -Node "pve1" -Builder $builder
```
Creates a new LXC container on node pve1 using a builder.
## PARAMETERS
### -Node
The node name.
```yaml
Type: String
Parameter Sets: (All)
Aliases:
Required: True
Position: 0
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```
### -Builder
The container builder.
```yaml
Type: ProxmoxContainerBuilder
Parameter Sets: (All)
Aliases:
Required: False
Position: 1
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False
```
### -CTID
The container ID.
```yaml
Type: Int32
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```
### -Name
The container name.
```yaml
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```
### -OSTemplate
The container OS template.
```yaml
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```
### -Storage
The container storage.
```yaml
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```
### -Memory
The container memory limit in MB.
```yaml
Type: Int32
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```
### -Swap
The container swap limit in MB.
```yaml
Type: Int32
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```
### -Cores
The container CPU cores.
```yaml
Type: Int32
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```
### -DiskSize
The container disk size in GB.
```yaml
Type: Int32
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```
### -Unprivileged
Whether the container is unprivileged.
```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```
### -Password
The container password.
```yaml
Type: SecureString
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```
### -SSHKey
The container SSH public key.
```yaml
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```
### -Description
The container description.
```yaml
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```
### -StartOnBoot
Whether to start the container on boot.
```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```
### -Start
Whether to start the container after creation.
```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```
### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
## INPUTS
### System.String
### PSProxmox.Models.ProxmoxContainerBuilder
### System.Int32
### System.Security.SecureString
### System.Management.Automation.SwitchParameter
## OUTPUTS
### PSProxmox.Models.ProxmoxContainer
## NOTES
## RELATED LINKS
@@ -0,0 +1,79 @@
# LXC Container Management Examples
# Connect to the Proxmox server
$securePassword = ConvertTo-SecureString "password" -AsPlainText -Force
Connect-ProxmoxServer -Server "proxmox.example.com" -Username "root" -Password $securePassword -Realm "pam"
# Get all LXC containers
$containers = Get-ProxmoxContainer
$containers | Format-Table -Property CTID, Name, Status, Node
# Get a specific LXC container
$container = Get-ProxmoxContainer -CTID 100
$container
# Get all LXC containers on a specific node
$nodeContainers = Get-ProxmoxContainer -Node "pve1"
$nodeContainers | Format-Table -Property CTID, Name, Status
# Get LXC containers by name pattern (wildcard)
$webContainers = Get-ProxmoxContainer -Name "web*"
$webContainers | Format-Table -Property CTID, Name, Status, Node
# Get LXC containers by name pattern (regex)
$dbContainers = Get-ProxmoxContainer -Name "^db\d+$"
$dbContainers | Format-Table -Property CTID, Name, Status, Node
# Create a new LXC container using parameters
$container = New-ProxmoxContainer -Node "pve1" -Name "web-container" -OSTemplate "local:vztmpl/ubuntu-20.04-standard_20.04-1_amd64.tar.gz" -Storage "local-lvm" -Memory 512 -Swap 512 -Cores 1 -DiskSize 8 -Unprivileged -StartOnBoot -Start
$container
# Create a new LXC container using a builder
$builder = New-ProxmoxContainerBuilder -Name "db-container"
$builder.WithOSTemplate("local:vztmpl/ubuntu-20.04-standard_20.04-1_amd64.tar.gz")
.WithStorage("local-lvm")
.WithMemory(1024)
.WithSwap(1024)
.WithCores(2)
.WithDiskSize(16)
.WithUnprivileged($true)
.WithStartOnBoot($true)
.WithStart($true)
.WithDescription("Database container")
$container = New-ProxmoxContainer -Node "pve1" -Builder $builder
$container
# Start an LXC container
Start-ProxmoxContainer -Node "pve1" -CTID 100 -Wait
Get-ProxmoxContainer -CTID 100
# Stop an LXC container
Stop-ProxmoxContainer -Node "pve1" -CTID 100 -Wait
Get-ProxmoxContainer -CTID 100
# Restart an LXC container
Restart-ProxmoxContainer -Node "pve1" -CTID 100 -Wait
Get-ProxmoxContainer -CTID 100
# Remove an LXC container
Remove-ProxmoxContainer -Node "pve1" -CTID 100 -Confirm:$false
# Get all TurnKey Linux templates
$templates = Get-ProxmoxTurnKeyTemplate
$templates | Format-Table -Property Name, Title, OS, Version, HumanSize
# Get TurnKey Linux templates by name pattern (wildcard)
$wordpressTemplates = Get-ProxmoxTurnKeyTemplate -Name "wordpress*"
$wordpressTemplates | Format-Table -Property Name, Title, OS, Version, HumanSize
# Download a TurnKey Linux template
$templatePath = Save-ProxmoxTurnKeyTemplate -Node "pve1" -Name "wordpress" -Storage "local"
$templatePath
# Create a new LXC container from a TurnKey Linux template
$container = New-ProxmoxContainerFromTurnKey -Node "pve1" -Name "wordpress" -Template "wordpress" -Storage "local-lvm" -Memory 512 -Cores 1 -DiskSize 8 -Start
$container
# Disconnect from the Proxmox server
Disconnect-ProxmoxServer
+172
View File
@@ -0,0 +1,172 @@
# LXC Container Management Guide
This guide covers how to use PSProxmox to manage LXC containers on a Proxmox VE server.
## Overview
Proxmox VE supports Linux Containers (LXC) as a lightweight alternative to full virtual machines. LXC containers provide an isolated environment for applications with minimal overhead compared to VMs.
PSProxmox provides cmdlets for creating, managing, and removing LXC containers, as well as working with TurnKey Linux templates.
## Container Management Cmdlets
PSProxmox includes the following cmdlets for managing LXC containers:
- `Get-ProxmoxContainer`: List all LXC containers or get details for a specific container
- `New-ProxmoxContainer`: Create a new LXC container
- `New-ProxmoxContainerBuilder`: Create a builder for configuring container parameters
- `Remove-ProxmoxContainer`: Delete an LXC container
- `Start-ProxmoxContainer`: Start an LXC container
- `Stop-ProxmoxContainer`: Stop an LXC container
- `Restart-ProxmoxContainer`: Restart an LXC container
## TurnKey Template Management Cmdlets
PSProxmox also includes cmdlets for working with TurnKey Linux templates:
- `Get-ProxmoxTurnKeyTemplate`: List available TurnKey templates
- `Save-ProxmoxTurnKeyTemplate`: Download a TurnKey template to a Proxmox storage
- `New-ProxmoxContainerFromTurnKey`: Create a new LXC container from a TurnKey template
## Basic Container Operations
### Listing Containers
To list all containers on a Proxmox server:
```powershell
Get-ProxmoxContainer
```
To get a specific container by ID:
```powershell
Get-ProxmoxContainer -CTID 100
```
To get containers on a specific node:
```powershell
Get-ProxmoxContainer -Node "pve1"
```
To get containers by name pattern (supports wildcards and regex):
```powershell
# Using wildcards
Get-ProxmoxContainer -Name "web*"
# Using regex
Get-ProxmoxContainer -Name "^web\d+$"
```
### Creating Containers
To create a new container using parameters:
```powershell
New-ProxmoxContainer -Node "pve1" -Name "web-container" -OSTemplate "local:vztmpl/ubuntu-20.04-standard_20.04-1_amd64.tar.gz" -Storage "local-lvm" -Memory 512 -Swap 512 -Cores 1 -DiskSize 8 -Unprivileged -StartOnBoot -Start
```
To create a new container using a builder (for more complex configurations):
```powershell
$builder = New-ProxmoxContainerBuilder -Name "db-container"
$builder.WithOSTemplate("local:vztmpl/ubuntu-20.04-standard_20.04-1_amd64.tar.gz")
.WithStorage("local-lvm")
.WithMemory(1024)
.WithSwap(1024)
.WithCores(2)
.WithDiskSize(16)
.WithUnprivileged($true)
.WithStartOnBoot($true)
.WithStart($true)
.WithDescription("Database container")
New-ProxmoxContainer -Node "pve1" -Builder $builder
```
### Managing Container State
To start a container:
```powershell
Start-ProxmoxContainer -Node "pve1" -CTID 100 -Wait
```
To stop a container:
```powershell
Stop-ProxmoxContainer -Node "pve1" -CTID 100 -Wait
```
To restart a container:
```powershell
Restart-ProxmoxContainer -Node "pve1" -CTID 100 -Wait
```
### Removing Containers
To remove a container:
```powershell
Remove-ProxmoxContainer -Node "pve1" -CTID 100 -Confirm:$false
```
## Working with TurnKey Linux Templates
TurnKey Linux provides pre-built appliances that can be used as templates for LXC containers.
### Listing TurnKey Templates
To list all available TurnKey templates:
```powershell
Get-ProxmoxTurnKeyTemplate
```
To list templates by name pattern:
```powershell
Get-ProxmoxTurnKeyTemplate -Name "wordpress*"
```
To include templates that have already been downloaded:
```powershell
Get-ProxmoxTurnKeyTemplate -IncludeDownloaded
```
### Downloading TurnKey Templates
To download a TurnKey template to a storage:
```powershell
Save-ProxmoxTurnKeyTemplate -Node "pve1" -Name "wordpress" -Storage "local"
```
### Creating Containers from TurnKey Templates
To create a container from a TurnKey template:
```powershell
New-ProxmoxContainerFromTurnKey -Node "pve1" -Name "wordpress" -Template "wordpress" -Storage "local-lvm" -Memory 512 -Cores 1 -DiskSize 8 -Start
```
## Best Practices
1. **Use Unprivileged Containers**: For better security, create unprivileged containers when possible.
2. **Resource Allocation**: Allocate appropriate resources (memory, CPU, disk) based on the container's purpose.
3. **Storage Selection**: Choose the appropriate storage type for your containers (local-lvm is often a good choice for performance).
4. **Naming Convention**: Use a consistent naming convention for your containers to make management easier.
5. **Template Management**: Download and maintain templates on a central storage for easy access from all nodes.
## Examples
See the [LXC Container Management Examples](../examples/LXC-Container-Management.ps1) for more detailed examples.
## Related Documentation
- [Proxmox VE LXC Documentation](https://pve.proxmox.com/wiki/Linux_Container)
- [TurnKey Linux](https://www.turnkeylinux.org/)