sidecartrait

command module
v0.0.0-...-9421b25 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

README

SidecarTrait

Deploy sidecar to workload or kubernetes native resources

Supported workloads:

  • Pod
  • ReplicaSet
  • StatefulSet
  • Deployment
  • ContainerizedWorkload

Prerequisites

Please follow common prerequisites to install OAM Controllers.

Getting started

  • Get the SidecarTrait project to your GOPATH
git clone https://github.com/oam-dev/catalog.git
  • Install CRD to your Kubernetes cluster
cd catalog/traits/sidecartrait/

make install
  • Run the SidecarTrait controller
go run main.go
ContainerizedWorkload
  • Apply the sample ContainerizedWorkload
$ kubectl create namespace sidecar-test
$ kubectl -n sidecar-test apply -f config/samples/containerized-workload/difinition
$ kubectl -n sidecar-test apply -f config/samples/containerized-workload/sample_component.yaml
$ kubectl -n sidecar-test apply -f config/samples/containerized-workload/sample_application_config.yaml
# ./config/samples/contaierized/sample_application_config.yaml

  ...
      traits:
        - trait:
            apiVersion: core.oam.dev/v1alpha2
            kind: SidecarTrait
            metadata:
              name: sample-sidecart
            spec:
              container:
                name: nginx-sidecar
                image: nginx:1.13.12
                ports:
                  - containerPort: 8080
                    name: sidecarport
              volumes:
                - name: data
                  emptyDir : {}
                - name: data2
                  emptyDir: {}
  • Verify SidecarTrait you should see a deployment created by ContainerizedWorkload
$ kubectl -n sidecar-test  get deployment
NAME                         READY   UP-TO-DATE   AVAILABLE   AGE
example-component   1/1     1            1           15s
$ kubectl -n sidecar-test get deployment -o yaml

  ...
      spec:
        containers:
        - env:
          - name: ALLOW_EMPTY_PASSWORD
            value: "yes"
          image: bitnami/redis:latest
          name: redis-main
          ports:
          - containerPort: 6379
            name: redisport
            protocol: TCP
        - image: nginx:1.13.12
          name: nginx-sidecar
          ports:
          - containerPort: 8080
            name: sidecarport
            protocol: TCP

        volumes:
        - emptyDir: {}
          name: data
        - emptyDir: {}
          name: data2
  ...

How it work?

Essentially, the SidecarTrait controller will patch the corresponding resources based on the workload spec.

In detail:

  • If the workload type is ContainerizedWorkload which has two child resources (Deployment and Service), SidecarTrait can deploy sidecar to Deployment
  • If the workload type is K8S native resources (StatefulSet, Deployment, Pod, ReplicaSet), SidecarTrait can deploy sidecar based on spec.template.spec.containers or spec.containers.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
api
v1alpha2
Package v1alpha2 contains API Schema definitions for the core v1alpha2 API group +kubebuilder:object:generate=true +groupName=core.oam.dev
Package v1alpha2 contains API Schema definitions for the core v1alpha2 API group +kubebuilder:object:generate=true +groupName=core.oam.dev

Jump to

Keyboard shortcuts

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