kubepose

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 8, 2025 License: MIT Imports: 24 Imported by: 0

README ยถ

kubepose

A minimalist tool to convert Compose specification files to Kubernetes manifests

Why kubepose?

kubepose provides a simpler alternative to kompose, focusing solely on converting Compose specifications to Kubernetes YAML files with:

  • โœจ Zero Configuration Your compose file is the only input needed
  • ๐ŸŽฏ Predictable Output Generates clean, standard Kubernetes manifests
  • ๐Ÿ”’ Immutable by Default Secrets and configmaps are created immutably

Installation

# Using go install
go install github.com/middle-management/kubepose/cmd/kubepose@latest

# Or download latest release from https://github.com/middle-management/kubepose/releases
curl -L "https://github.com/middle-management/kubepose/releases/latest/download/kubepose-$(uname -s)-$(uname -m)" -o kubepose

# Make it executable
chmod +x kubepose

# Move it somewhere in your PATH
sudo mv kubepose /usr/local/bin/
Verify the signature of the release

The releases are signed using cosign. To verify the signature, you need to install cosign first.

# first download the certificate and signature files
curl -L "https://github.com/middle-management/kubepose/releases/latest/download/kubepose-$(uname -s)-$(uname -m).pem" -o kubepose-$(uname -s)-$(uname -m).pem
curl -L "https://github.com/middle-management/kubepose/releases/latest/download/kubepose-$(uname -s)-$(uname -m).sig" -o kubepose-$(uname -s)-$(uname -m).sig

# then use cosign to verify the signature
cosign verify-blob \
  --certificate kubepose-$(uname -s)-$(uname -m).pem \
  --signature kubepose-$(uname -s)-$(uname -m).sig \
  --certificate-identity "https://github.com/middle-management/kubepose/.github/workflows/release.yaml@refs/tags/<tag-version>" \
  --certificate-oidc-issuer "https://token.actions.githubusercontent.com" \
  kubepose-$(uname -s)-$(uname -m)

Quick Start

# Convert compose files to K8s manifests
kubepose convert

# Specify input files explicitly
kubepose convert -f compose.yaml -f compose.prod.yaml

# Use with kubectl
kubepose convert | kubectl apply -n my-ns -f -

# Use with specific profiles
kubepose convert -p prod

kubepose follows the same file lookup order as docker compose:

compose.yaml
compose.yml
docker-compose.yaml
docker-compose.yml

Examples

The tests in the testdata directory are integration tests which also work as examples of various Compose configurations and their corresponding Kubernetes output. Each feature has its own directory with a compose.yaml and its converted Kubernetes manifests in the TestConvert directory. See testdata/simple/compose.yaml and its corresponding testdata/TestConvert/simple/k8s.yaml as an example.

Key Features

  • ๐ŸŽฎ Simple CLI - Single command with familiar -f and -p flags
  • ๐Ÿš€ Application First - Focus on deploying applications, not managing clusters
  • ๐Ÿ”„ Standard Conversion - Predictable mapping to Kubernetes resources
  • ๐Ÿ“ฆ No Dependencies - Single binary with zero runtime requirements
  • ๐ŸŽฏ Targeted Scope - Focused purely on Compose to Kubernetes conversion

Supported Resources

Core Workloads
Feature Status Description
Deployments โœ… Default workload type
DaemonSets โœ… Enable with deploy.mode: global
Multi-Container Pods โœ… Group via kompose.service.group
Init Containers โœ… Mark with kubepose.container.type: init
Sidecar Containers โœ… Init containers with restart: always
StatefulSets ๐Ÿšง Planned
CronJobs ๐Ÿšง Planned
Container Configuration
Feature Status Description
Image & Tags โœ… Full support for image references
Commands โœ… Both command and entrypoint
Update Strategies โœ… Configurable update behavior
Environment โœ… Variables and values
Working Directory โœ… Via working_dir
Shell Access โœ… stdin_open and tty
Resource Limits โœ… CPU and memory constraints
Health Checks โœ… Supports test commands and HTTP checks
User Settings โœ… Numeric user/group IDs only
Networking
Feature Status Description
Ports โœ… TCP/UDP port mapping
Service Exposure โœ… Via Kubernetes annotations
Internal DNS โŒ Use Kubernetes DNS instead
Custom Networks โŒ Use Kubernetes networking
Storage & State
Feature Status Description
Named Volumes โœ… Converts to PersistentVolumeClaims
Bind Mounts โœ… Creates ConfigMaps for files
Host Paths โœ… Via kubepose.volume.hostPath label
Tmpfs โœ… Maps to emptyDir with Memory medium
Volume Labels โœ… Preserved in K8s resources
Configuration & Secrets
Feature Status Description
File-based Secrets โœ… Creates Kubernetes Secrets
Environment Secrets โœ… Creates Kubernetes Secrets
External Secrets โœ… References existing K8s Secrets
Labels โœ… Preserved in K8s resources
Annotations โœ… Preserved in K8s resources
Profiles โœ… For environment-specific configs

Unsupported Features

Some Docker Compose features are intentionally not supported as they either:

  • Have no direct Kubernetes equivalent
  • Are better handled by native Kubernetes features
  • Fall outside kubepose's scope

Key unsupported features include:

  • ๐Ÿ› ๏ธ Build configuration (use docker buildkit bake)
  • ๐Ÿ”— Container linking (use Kubernetes Services)
  • ๐Ÿ—๏ธ Dependencies (use Kubernetes primitives)
  • ๐Ÿ” Privileged mode and capabilities
  • ๐Ÿ“ Logging configuration

Best Practices

  1. Use Profiles for environment-specific configurations
  2. Leverage Labels for better resource organization
  3. Keep Secrets External when possible
  4. Use Standard Ports to maintain compatibility

Status Legend

Symbol Meaning
โœ… Fully Supported
๐Ÿšง Coming Soon
โŒ Not Supported
Update Strategies

kubepose supports Docker Compose's update_config for controlling how services are updated:

services:
  web:
    deploy:
      update_config:
        parallelism: 2     # How many containers to update at once
        order: start-first # Update strategy: start-first, stop-first
        delay: 10s        # Minimum time between updates
        monitor: 60s      # Time to monitor for failure

The configuration maps to Kubernetes deployment strategies as follows:

Compose Config Deployment DaemonSet Description
order: start-first RollingUpdate with maxUnavailable: 0 RollingUpdate with maxSurge Start new pods before stopping old
order: stop-first Recreate RollingUpdate with maxUnavailable Stop old pods before starting new
parallelism maxSurge/maxUnavailable maxSurge/maxUnavailable Number of pods updated at once
delay minReadySeconds minReadySeconds Time between updates
monitor progressDeadlineSeconds N/A Time to monitor for failures

Example configurations:

# Rolling update that starts new pods first
services:
  web:
    deploy:
      update_config:
        order: start-first
        parallelism: 2

# Stop all pods before starting new ones
services:
  db:
    deploy:
      update_config:
        order: stop-first

# Gradual rollout with monitoring
services:
  api:
    deploy:
      update_config:
        parallelism: 1
        delay: 30s
        monitor: 60s

Note that some aspects of Docker Compose's update configuration don't have direct equivalents in Kubernetes:

  • failure_action is handled differently through Kubernetes' native deployment controller
  • max_failure_ratio has no direct equivalent

Contributing

Contributions are welcome! See our Contributing Guide for details.

License

MIT License

Documentation ยถ

Index ยถ

Constants ยถ

View Source
const (
	AppSelectorLabelKey                        = "app.kubernetes.io/name"
	ServiceGroupAnnotationKey                  = "kubepose.service.group"
	ServiceAccountNameAnnotationKey            = "kubepose.service.serviceAccountName"
	ServiceExposeAnnotationKey                 = "kubepose.service.expose"
	ServiceExposeIngressClassNameAnnotationKey = "kubepose.service.expose.ingressClassName"
	SelectorMatchLabelsAnnotationKey           = "kubepose.selector.matchLabels"
	HealthcheckHttpGetPathAnnotationKey        = "kubepose.healthcheck.http_get.path"
	HealthcheckHttpGetPortAnnotationKey        = "kubepose.healthcheck.http_get.port"
	ContainerTypeAnnotationKey                 = "kubepose.container.type"
	ConfigHmacKeyAnnotationKey                 = "kubepose.config.hmac-key"
	SecretHmacKeyAnnotationKey                 = "kubepose.secret.hmac-key"
	VolumeHmacKeyAnnotationKey                 = "kubepose.volume.hmac-key"
	VolumeHostPathLabelKey                     = "kubepose.volume.hostPath"
	VolumeStorageClassNameLabelKey             = "kubepose.volume.storageClassName"
	VolumeSizeLabelKey                         = "kubepose.volume.size"
	SecretSubPathLabelKey                      = "kubepose.secret.subPath"
)

Variables ยถ

This section is empty.

Functions ยถ

This section is empty.

Types ยถ

type ConfigMapping ยถ

type ConfigMapping struct {
	Name     string
	External bool
}

type Resources ยถ

type Resources struct {
	Pods                   []*corev1.Pod
	Secrets                []*corev1.Secret
	Services               []*corev1.Service
	ConfigMaps             []*corev1.ConfigMap
	DaemonSets             []*appsv1.DaemonSet
	Deployments            []*appsv1.Deployment
	Ingresses              []*networkingv1.Ingress
	PersistentVolumeClaims []*corev1.PersistentVolumeClaim
	ServiceAccounts        []*corev1.ServiceAccount
}

func (*Resources) Write ยถ

func (r *Resources) Write(writer io.Writer) error

type SecretMapping ยถ

type SecretMapping struct {
	Name     string
	External bool
	SubPath  string
}

type Transformer ยถ

type Transformer struct {
	Annotations map[string]string
	Labels      map[string]string
}

func (Transformer) Convert ยถ

func (t Transformer) Convert(project *types.Project) (*Resources, error)

type VolumeMapping ยถ

type VolumeMapping struct {
	Name          string
	ConfigMapName string
	MountPath     string
	HostPath      string
	IsConfigMap   bool
	IsHostPath    bool
	IsTmpfs       bool
	TmpfsSize     *resource.Quantity
}

Directories ยถ

Path Synopsis
cmd
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL