cpln convert

Overview

The cpln convert command is designed to facilitate the migration from Kubernetes environments to Control Plane by converting Kubernetes objects into Control Plane objects.

Typically, this command is utilized alongside the cpln apply command to seamlessly convert and then directly apply the configurations.

Prerequisites

Options

Required

  • --file
    • A JSON/YAML file containing Kubernetes objects. Use --file - to enable input from stdin.

Optional

  • --protocol
    • The port protocol to be assigned to each container within a workload converted from a deployment. Default: http. [choices: http, http2, grpc, tcp].

Limitations

The cpln convert command has specific conversion capabilities, detailed as follows:

  • Workloads Conversion
    • Can convert objects of kind Deployment and CronJob into workloads.
  • Secrets Conversion
    • Capable of converting objects of kind Secret into Control Plane secrets.

Create a K8s file

To demonstrate the convert command, create a k8s.yaml file with the following content:

copy
apiVersion: apps/v1
kind: Deployment
metadata:
name: example-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80

Convert a K8s file

Basic Convert

The following command will convert the Kubernetes object defined in the above k8s.yaml file into a Control Plane object and output it to the terminal.

copy
cpln convert --file k8s.yaml
Output
copy
kind: workload
name: example-deployment
spec:
containers:
- name: nginx
image: 'nginx:latest'
env: []
ports:
- number: 80
protocol: http
args: []
defaultOptions:
suspend: false
capacityAI: false
autoscaling:
minScale: 3
maxScale: 3
type: serverless

Convert With a Specific Protocol

Each Kubernetes object, whether of type Deployment or CronJob, will be transformed into workloads. These workloads will feature containers whose port protocols are aligned with the specification provided in the --protocol option.

copy
cpln convert --file k8s.yaml --protocol tcp
Output
copy
kind: workload
name: example-deployment
spec:
containers:
- name: nginx
image: 'nginx:latest'
env: []
ports:
- number: 80
protocol: tcp
args: []
defaultOptions:
suspend: false
capacityAI: false
autoscaling:
minScale: 3
maxScale: 3
type: serverless

Convert & Apply

Use the cpln apply command to convert and apply.

copy
cpln apply --file k8s.yaml --k8s true

Alternatively, you can pass the conversion result as a stdin to the cpln apply command.

cpln convert --file k8s.yaml | cpln apply --file -

Revert Apply

To revert the apply, use the following command.

copy
cpln delete --file k8s.yaml --k8s true
Copyright © 2024 Control Plane Corporation. All rights reserved. Revision 44e6d472
Contents