Create Helm-charts, Kustomize overlays from Kubernetes Yamls

In this tutorial we will see how to transform a set of Kubernetes YAMLs by parameterizing them. We can use Move2Kube to generate parameterized Helm charts, Kustomize and Openshift Templates from the Kubernetes YAMLs. Move2Kube can also change the version of Kubernetes resources to target particular clusters.

Prerequisites

  • Move2Kube CLI tool is installed
  • Use a kubernetes-to-kubernetes sample. The kubernetes-to-kubernetes directory has some Kubernetes YAMLs that deploy a web app with multiple services. There are three services: a frontend website in PHP, a backend API in Node.JS, and a cache service using Redis.

Procedure

  1. Download the kubernetes-to-kubernetes sample.
  $ curl https://move2kube.konveyor.io/scripts/download.sh | bash -s -- -d samples/kubernetes-to-kubernetes -r move2kube-demos
  $ ls kubernetes-to-kubernetes/
  api-deployment.yaml  api-service.yaml  redis-deployment.yaml  redis-service.yaml  web-deployment.yaml  web-ingress.yaml  web-service.yaml
  1. Run move2kube plan -s kubernetes-to-kubernetes/ to generate a plan file.
$ move2kube plan -s kubernetes-to-kubernetes/
INFO[0000] Configuration loading done
INFO[0000] Planning Transformation - Base Directory
INFO[0000] [ComposeAnalyser] Planning transformation
INFO[0000] [ComposeAnalyser] Done
INFO[0000] [CloudFoundry] Planning transformation
INFO[0000] [CloudFoundry] Done
INFO[0000] [DockerfileDetector] Planning transformation
INFO[0000] [DockerfileDetector] Done
INFO[0000] [Base Directory] Identified 0 named services and 0 to-be-named services
INFO[0000] Transformation planning - Base Directory done
INFO[0000] Planning Transformation - Directory Walk
INFO[0000] Identified 1 named services and 0 to-be-named services in .
INFO[0000] Identified 1 named services and 0 to-be-named services in .
INFO[0000] Transformation planning - Directory Walk done
INFO[0000] [Directory Walk] Identified 1 named services and 1 to-be-named services
INFO[0000] [Named Services] Identified 1 named services
INFO[0000] No of services identified : 1
INFO[0000] Plan can be found at [/home/user/m2k.plan].
  1. Look at the generated plan-file in YAML format.
$ ls
kubernetes-to-kubernetes	m2k.plan
$ cat m2k.plan

Notice that Move2Kube has detected all the different services, one for each web app.

aapiVersion: move2kube.konveyor.io/v1alpha1
 kind: Plan
 metadata:
   name: myproject
 spec:
   sourceDir: kubernetes-to-kubernetes
   services:
     myproject:
       - transformerName: KubernetesVersionChanger
         type: KubernetesOrgYamlsInSource
         paths:
           KubernetesYamls:
             - .
           ServiceDirPath:
             - .
       - transformerName: Parameterizer
         paths:
           KubernetesYamls:
             - .
           ServiceDirPath:
             - .
   transformers:
     Buildconfig: m2kassets/built-in/transformers/kubernetes/buildconfig/buildconfig.yaml
     CloudFoundry: m2kassets/built-in/transformers/cloudfoundry/cloudfoundry.yaml
     ClusterSelector: m2kassets/built-in/transformers/kubernetes/clusterselector/clusterselector.yaml
     ComposeAnalyser: m2kassets/built-in/transformers/compose/composeanalyser/composeanalyser.yaml
     ComposeGenerator: m2kassets/built-in/transformers/compose/composegenerator/composegenerator.yaml
     ContainerImagesPushScriptGenerator: m2kassets/built-in/transformers/containerimage/containerimagespushscript/containerimagespushscript.yaml
     DockerfileDetector: m2kassets/built-in/transformers/dockerfile/dockerfiledetector/dockerfiledetector.yaml
     DockerfileImageBuildScript: m2kassets/built-in/transformers/dockerfile/dockerimagebuildscript/dockerfilebuildscriptgenerator.yaml
     DockerfileParser: m2kassets/built-in/transformers/dockerfile/dockerfileparser/dockerfileparser.yaml
     DotNetCore-Dockerfile: m2kassets/built-in/transformers/dockerfilegenerator/dotnetcore/dotnetcore.yaml
     EarAnalyser: m2kassets/built-in/transformers/dockerfilegenerator/java/earanalyser/ear.yaml
     EarRouter: m2kassets/built-in/transformers/dockerfilegenerator/java/earrouter/earrouter.yaml
     Golang-Dockerfile: m2kassets/built-in/transformers/dockerfilegenerator/golang/golang.yaml
     Gradle: m2kassets/built-in/transformers/dockerfilegenerator/java/gradle/gradle.yaml
     Jar: m2kassets/built-in/transformers/dockerfilegenerator/java/jar/jar.yaml
     Jboss: m2kassets/built-in/transformers/dockerfilegenerator/java/jboss/jboss.yaml
     Knative: m2kassets/built-in/transformers/kubernetes/knative/knative.yaml
     Kubernetes: m2kassets/built-in/transformers/kubernetes/kubernetes/kubernetes.yaml
     KubernetesVersionChanger: m2kassets/built-in/transformers/kubernetes/kubernetesversionchanger/kubernetesversionchanger.yaml
     Liberty: m2kassets/built-in/transformers/dockerfilegenerator/java/liberty/liberty.yaml
     Maven: m2kassets/built-in/transformers/dockerfilegenerator/java/maven/maven.yaml
     Nodejs-Dockerfile: m2kassets/built-in/transformers/dockerfilegenerator/nodejs/nodejs.yaml
     PHP-Dockerfile: m2kassets/built-in/transformers/dockerfilegenerator/php/php.yaml
     Parameterizer: m2kassets/built-in/transformers/kubernetes/parameterizer/parameterizer.yaml
     Python-Dockerfile: m2kassets/built-in/transformers/dockerfilegenerator/python/python.yaml
     ReadMeGenerator: m2kassets/built-in/transformers/readmegenerator/readmegenerator.yaml
     Ruby-Dockerfile: m2kassets/built-in/transformers/dockerfilegenerator/ruby/ruby.yaml
     Rust-Dockerfile: m2kassets/built-in/transformers/dockerfilegenerator/rust/rust.yaml
     Tekton: m2kassets/built-in/transformers/kubernetes/tekton/tekton.yaml
     Tomcat: m2kassets/built-in/transformers/dockerfilegenerator/java/tomcat/tomcat.yaml
     WarAnalyser: m2kassets/built-in/transformers/dockerfilegenerator/java/waranalyser/war.yaml
     WarRouter: m2kassets/built-in/transformers/dockerfilegenerator/java/warrouter/warrouter.yaml
     WinConsoleApp-Dockerfile: m2kassets/built-in/transformers/dockerfilegenerator/windows/winconsole/winconsole.yaml
     WinSLWebApp-Dockerfile: m2kassets/built-in/transformers/dockerfilegenerator/windows/winsilverlightweb/winsilverlightweb.yaml
     WinWebApp-Dockerfile: m2kassets/built-in/transformers/dockerfilegenerator/windows/winweb/winweb.yaml
     ZuulAnalyser: m2kassets/built-in/transformers/dockerfilegenerator/java/zuul/zuulanalyser.yaml
  1. Run the transformation using move2kube transform.
$ move2kube transform
INFO[0000] Detected a plan file at path /home/user/m2k.plan. Will transform using this plan.
? Select all transformer types that you are interested in:
ID: move2kube.transformers.types
Hints:
[Services that don't support any of the transformer types you are interested in will be ignored.]
 ComposeAnalyser, PHP-Dockerfile, ReadMeGenerator, Ruby-Dockerfile, Tekton, Buildconfig, Golang-Dockerfile, Jar, Knative, Nodejs-Dockerfile, Parameterizer, CloudFoundry, DockerfileDetector, Kubernetes, Maven, WinWebApp-Dockerfile, Gradle, KubernetesVersionChanger, WarAnalyser, Rust-Dockerfile, WarRouter, ZuulAnalyser, DotNetCore-Dockerfile,EarRouter, Liberty, Python-Dockerfile, Tomcat, ContainerImagesPushScriptGenerator, DockerfileImageBuildScript, DockerfileParser, ClusterSelector, ComposeGenerator,   EarAnalyser, Jboss, WinConsoleApp-Dockerfile, WinSLWebApp-Dockerfile
? Select all services that are needed:
ID: move2kube.services.[].enable
Hints:
[The services unselected here will be ignored.]
Click to see the remaining output.