app2kube

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2019 License: Apache-2.0 Imports: 30 Imported by: 0

README

app2kube

The easiest way to create and apply kubernetes manifests for an application

Features

  • Simple deployment to kubernetes without knowledge of manifest syntax
  • There are no built-in manifest templates under the hood, only native kubernetes objects
  • Understandable set of values for configuration in YAML
  • Templating values in YAML file with sprig functions
  • Supported Kubernetes resources:
    • ConfigMap
    • CronJob
    • Deployment
    • Ingress
    • Namespace
    • PersistentVolumeClaim
    • Secret
    • Service
  • Secret value encryption with AES-256 CBC
  • Support staging
  • Build and push docker image
  • Apply/delete a configuration to a resource in kubernetes
  • Track application deployment in kubernetes
  • Portable - apply/delete command ported from kubectl, build from docker-cli

Install

Download binaries from release page.

Or install from source:

go get -u github.com/n0madic/app2kube/cmd/app2kube

Help

Usage:
  app2kube [command]

Available Commands:
  apply       Apply a configuration to a resource in kubernetes
  build       Build and push an image from a Dockerfile
  completion  Generates bash completion scripts
  delete      Delete resources from kubernetes
  encrypt     Encrypt secret values in YAML file
  help        Help about any command
  manifest    Generate kubernetes manifests for an application
  track       Track application deployment in kubernetes

Flags:
      --certificate-authority string   Path to a cert file for the certificate authority
      --client-certificate string      Path to a client certificate file for TLS
      --client-key string              Path to a client key file for TLS
      --cluster string                 The name of the kubeconfig cluster to use
      --context string                 The name of the kubeconfig context to use
  -h, --help                           help for app2kube
      --insecure-skip-tls-verify       If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure
      --kubeconfig string              Path to the kubeconfig file to use for CLI requests.
  -n, --namespace string               If present, the namespace scope for this CLI request
      --request-timeout string         The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0")
  -s, --server string                  The address and port of the Kubernetes API server
      --token string                   Bearer token for authentication to the API server
      --user string                    The name of the kubeconfig user to use
      --version                        version for app2kube

Usage

Minimum required values for application deployment in kubernetes - name and image.

app2kube manifest --set name=example --set deployment.containers.example.image=example/image:latest

By default, it tries to use the .app2kube.yml file in the current directory:

---
name: example
deployment:
  containers:
    example:
      image: "example/image:latest"

OR

---
name: example
common:
  image:
    repository: "example/image"
    tag: "latest"
deployment:
  containers:
    example: {}

Get kubernetes manifest:

app2kube manifest

Build and push docker image:

app2kube build --push

Apply application manifest in kubernetes:

app2kube apply

Track deployment till ready:

app2kube track ready

Delete application manifest from kubernetes:

app2kube delete

Staging

For a staging release, you must set the staging and optional branch parameters:

app2kube manifest --set staging=alpha --set branch=develop

In this case, some values will be reset to more optimal for staging:

common:
  image:
    pullPolicy: Always
deployment:
  replicaCount: 1
  revisionHistoryLimit: 0

Also, aliases for ingress and resource requests for containers (for a denser filling of the staging environment) will not be used.

For ingress domains, prefixes from the above values will be automatically added: staging.example.com or branch.staging.example.com

Examples

Simple web service:

---
name: example
deployment:
  containers:
    example:
      image: "example/image:latest"
      ports:
      - containerPort: 8080
        name: http
      readinessProbe:
        httpGet:
          path: /healthz
ingress:
- host: "example.com"

PHP-FPM application with web service (common image) and cron jobs, include memcached:

---
name: example
common:
  image:
    repository: "example/php-nginx"
    tag: "7.3"
cronjob:
  cleaning:
    schedule: "0 0 * * *"
    container:
      command: ["/usr/bin/php"]
      args: ["/var/www/cron.php", "--cleaning"]
deployment:
  containers:
    php-fpm:
      command: ["/usr/sbin/php-fpm7.3"]
      args: ["--nodaemonize", "--force-stderr"]
      resources:
        requests:
          memory: 350Mi
          cpu: 10m
      livenessProbe:
        tcpSocket:
          port: 9000
    nginx:
      command: ["/usr/sbin/nginx"]
      args: ["-g", "daemon off;"]
      lifecycle:
        preStop:
          exec:
            command: ["/usr/sbin/nginx", "-s"," quit"]
      livenessProbe:
        tcpSocket:
          port: 80
      readinessProbe:
        httpGet:
          port: 80
          path: /
        timeoutSeconds: 60
    memcached:
      image: "memcached:alpine"
      imagePullPolicy: IfNotPresent
      livenessProbe:
        tcpSocket:
          port: 11211
service:
  http:
    port: 80
ingress:
- host: "example.com"
  aliases:
  - "www.example.com"
  letsencrypt: true
  sslRedirect: true

Documentation

Index

Constants

View Source
const CryptPrefix = "CRYPT#"

CryptPrefix for encrypted values

View Source
const NamespaceDefault = apiv1.NamespaceDefault

NamespaceDefault means the object is in the default namespace which is applied when not specified by clients

Variables

This section is empty.

Functions

func DecryptAES

func DecryptAES(password string, crypt64 string) (string, error)

DecryptAES base64 string encoded by the AES-256 CBC

func EncryptAES

func EncryptAES(password string, plaintext string) (string, error)

EncryptAES text with AES-256 CBC and returns a base64 encoded string

func GetPassword

func GetPassword() (string, error)

GetPassword for environment variable $APP2KUBE_PASSWORD

func PrintObj

func PrintObj(obj runtime.Object, output string) (string, error)

PrintObj return manifest from object

Types

type App

type App struct {
	Branch string `yaml:"branch"`
	Common struct {
		CronjobSuspend     bool            `yaml:"cronjobSuspend"`
		DNSPolicy          apiv1.DNSPolicy `yaml:"dnsPolicy"`
		EnableServiceLinks bool            `yaml:"enableServiceLinks"`
		GracePeriod        int64           `yaml:"gracePeriod"`
		Image              struct {
			PullPolicy  apiv1.PullPolicy `yaml:"pullPolicy"`
			PullSecrets string           `yaml:"pullSecrets"`
			Repository  string           `yaml:"repository"`
			Tag         string           `yaml:"tag"`
		} `yaml:"image"`
		Ingress struct {
			IngressCommon
		} `yaml:"ingress"`
		MountServiceAccountToken bool               `yaml:"mountServiceAccountToken"`
		NodeSelector             map[string]string  `yaml:"nodeSelector"`
		SharedData               string             `yaml:"sharedData"`
		Tolerations              []apiv1.Toleration `yaml:"tolerations"`
	} `yaml:"common"`
	ConfigMap map[string]string `yaml:"configmap"`
	Cronjob   map[string]struct {
		ConcurrencyPolicy          batch.ConcurrencyPolicy `yaml:"concurrencyPolicy"`
		Container                  apiv1.Container         `yaml:"container"`
		FailedJobsHistoryLimit     int32                   `yaml:"failedJobsHistoryLimit"`
		RestartPolicy              apiv1.RestartPolicy     `yaml:"restartPolicy"`
		Schedule                   string                  `yaml:"schedule"`
		SuccessfulJobsHistoryLimit int32                   `yaml:"successfulJobsHistoryLimit"`
		Suspend                    bool                    `yaml:"suspend"`
	} `yaml:"cronjob"`
	Deployment struct {
		Containers           map[string]apiv1.Container `yaml:"containers"`
		ReplicaCount         int32                      `yaml:"replicaCount"`
		RevisionHistoryLimit int32                      `yaml:"revisionHistoryLimit"`
		Strategy             appsv1.DeploymentStrategy  `yaml:"strategy"`
	} `yaml:"deployment"`
	Env       map[string]string  `yaml:"env"`
	Ingress   []Ingress          `yaml:"ingress"`
	Labels    map[string]string  `yaml:"labels"`
	Name      string             `yaml:"name"`
	Namespace string             `yaml:"namespace"`
	Secrets   map[string]string  `yaml:"secrets"`
	Service   map[string]Service `yaml:"service"`
	Staging   string             `yaml:"staging"`
	Volumes   map[string]struct {
		Spec      apiv1.PersistentVolumeClaimSpec `yaml:"spec"`
		MountPath string                          `yaml:"mountPath"`
	} `yaml:"volumes"`
}

App instance

func NewApp

func NewApp() *App

NewApp return App instance

func (*App) GetConfigMap

func (app *App) GetConfigMap() (configmap *apiv1.ConfigMap, err error)

GetConfigMap resource

func (*App) GetCronJobs

func (app *App) GetCronJobs() (crons []*batch.CronJob, err error)

GetCronJobs resource

func (*App) GetDeployment

func (app *App) GetDeployment() (deployment *appsv1.Deployment, err error)

GetDeployment resource

func (*App) GetIngress

func (app *App) GetIngress() (ingress []*v1beta1.Ingress, err error)

GetIngress resource

func (*App) GetIngressSecrets

func (app *App) GetIngressSecrets() (secrets []*apiv1.Secret)

GetIngressSecrets return TLS secrets for ingress

func (*App) GetManifest

func (app *App) GetManifest(outputFormat string, typeOutput ...OutputResource) (manifest string, err error)

GetManifest returns a manifest with the specified resource types

func (*App) GetNamespace

func (app *App) GetNamespace() (namespace *apiv1.Namespace)

GetNamespace resource

func (*App) GetObjectMeta

func (app *App) GetObjectMeta(name string) metav1.ObjectMeta

GetObjectMeta return App metadata

func (*App) GetPersistentVolumeClaims

func (app *App) GetPersistentVolumeClaims() (claims []*apiv1.PersistentVolumeClaim, err error)

GetPersistentVolumeClaims resource

func (*App) GetReleaseName

func (app *App) GetReleaseName() string

GetReleaseName of App

func (*App) GetSecret

func (app *App) GetSecret() (secret *apiv1.Secret, err error)

GetSecret resource

func (*App) GetServices

func (app *App) GetServices() (services []*apiv1.Service, err error)

GetServices resource

func (*App) LoadValues

func (app *App) LoadValues(valueFiles ValueFiles, values, stringValues, fileValues []string) ([]byte, error)

LoadValues for App

type Ingress

type Ingress struct {
	IngressCommon
	Aliases       []string `yaml:"aliases"`
	Host          string   `yaml:"host"`
	Letsencrypt   bool     `yaml:"letsencrypt"`
	Path          string   `yaml:"path"`
	SslRedirect   bool     `yaml:"sslRedirect"`
	TLSCrt        string   `yaml:"tlsCrt"`
	TLSKey        string   `yaml:"tlsKey"`
	TLSSecretName string   `yaml:"tlsSecretName"`
}

Ingress specification

type IngressCommon added in v0.2.0

type IngressCommon struct {
	Annotations map[string]string `yaml:"annotations"`
	Class       string            `yaml:"class"`
	ServiceName string            `yaml:"serviceName"`
	ServicePort int32             `yaml:"servicePort"`
}

IngressCommon specification

type OutputResource

type OutputResource int

OutputResource type

const (
	// OutputAll for all resources (except namespace)
	OutputAll OutputResource = iota
	// OutputConfigMap only
	OutputConfigMap
	// OutputCronJob only
	OutputCronJob
	// OutputDeployment only
	OutputDeployment
	// OutputIngress only
	OutputIngress
	// OutputNamespace only
	OutputNamespace
	// OutputPersistentVolumeClaim only
	OutputPersistentVolumeClaim
	// OutputSecret only
	OutputSecret
	// OutputService only
	OutputService
)

type Service

type Service struct {
	ExternalPort int32             `yaml:"externalPort"`
	InternalPort int32             `yaml:"internalPort"`
	Port         int32             `yaml:"port"`
	Protocol     apiv1.Protocol    `yaml:"protocol"`
	Type         apiv1.ServiceType `yaml:"type"`
}

Service specification

type ValueFiles

type ValueFiles []string

ValueFiles list

func (*ValueFiles) Set

func (v *ValueFiles) Set(value string) error

Set ValueFiles

func (*ValueFiles) String

func (v *ValueFiles) String() string

func (*ValueFiles) Type

func (v *ValueFiles) Type() string

Type ValueFiles

Directories

Path Synopsis
cmd
pkg
cmd

Jump to

Keyboard shortcuts

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