Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support pod injection to deploy layotto as a sidecar in Kubernetes #993

Merged
merged 8 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion .github/workflows/layotto-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,12 @@ jobs:
- name: Push Image to DockerHub
run: |
make image.push.linux_amd64.layotto VERSION=latest
- name: Build layotto/injector:latest Image
run: |
make image.build.linux_amd64.injector VERSION=latest
- name: Push layotto/injector:latest Image to DockerHub
run: |
make image.push.linux_amd64.injector VERSION=latest
- name: Build layotto/proxyv2:latest Image
run: |
make image.proxyv2.build VERSION=latest
Expand All @@ -280,7 +286,7 @@ jobs:
make image.proxyv2.push VERSION=latest

build-push-linux-arm64-image:
name: "Linux ARMD64 Image"
name: "Linux ARM64 Image"
needs: [build-wasm-binary-linux-amd64-artifact,build-binary-linux-arm64-artifact,build-binary-linux-amd64-artifact,build-binary-darwin-amd64-artifact,build-binary-darwin-arm64-artifact]
if: github.ref_name == 'main'
runs-on: ubuntu-latest
Expand All @@ -302,3 +308,23 @@ jobs:
- name: Push Image to DockerHub
run: |
make image.push.linux_arm64.layotto VERSION=latest
- name: Build layotto/injector:latest Image
run: |
make image.build.linux_arm64.injector VERSION=latest
- name: Push layotto/injector:latest Image to DockerHub
run: |
make image.push.linux_arm64.injector VERSION=latest

package-push-injector-helm-chart:
name: "Layotto Injector Helm Chart"
if: github.ref_name == 'main'
runs-on: ubuntu-latest
steps:
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Package and Push Injector Latest Helm Chart
run: |
CHART_VERSION=v0.0.0-latest APP_VERSION=latest make helm-package helm-push
27 changes: 26 additions & 1 deletion .github/workflows/layotto-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,15 @@ jobs:
- name: Push Image to DockerHub
run: |
make image.push.linux_amd64.layotto
- name: Build layotto/injector:latest Image
run: |
make image.build.linux_amd64.injector VERSION=latest
- name: Push layotto/injector:latest Image to DockerHub
run: |
make image.push.linux_amd64.injector VERSION=latest

build-push-linux-arm64-image:
name: "Linux ARMD64 Image"
name: "Linux ARM64 Image"
needs: [build-wasm-binary-linux-amd64-artifact,build-binary-linux-arm64-artifact,build-binary-linux-amd64-artifact,build-binary-darwin-amd64-artifact,build-binary-darwin-arm64-artifact]
runs-on: ubuntu-latest
steps:
Expand All @@ -328,3 +334,22 @@ jobs:
- name: Push Image to DockerHub
run: |
make image.push.linux_arm64.layotto
- name: Build layotto/injector:latest Image
run: |
make image.build.linux_arm64.injector VERSION=latest
- name: Push layotto/injector:latest Image to DockerHub
run: |
make image.push.linux_arm64.injector VERSION=latest

package-push-injector-helm-chart:
name: "Layotto Injector Helm Chart"
runs-on: ubuntu-latest
steps:
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Package and Push Injector Latest Helm Chart
run: |
CHART_VERSION=v0.0.0-latest APP_VERSION=latest make helm-package helm-push
2 changes: 1 addition & 1 deletion cmd/layotto_injector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ func main() {
if err != nil {
log.Fatalf("Error running layotto-injector: %v", err)
}
log.Info("Layotto sidecar layotto-injector shut down gracefully")
log.Info("Layotto sidecar injector shutdown gracefully")
}
5 changes: 1 addition & 4 deletions demo/state/k8s/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ FROM golang:1.18-alpine AS build-env

WORKDIR /app

COPY ../../../deploy/k8s/state .
COPY . .

RUN go build -o client client.go

FROM alpine:latest
RUN apk --no-cache add ca-certificates
COPY --from=build-env /app/client .
COPY config.json /usr/share/layotto/configure/
EXPOSE 8443
CMD [ "./client", "-s", "state_demo" ]
11 changes: 3 additions & 8 deletions demo/state/k8s/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,15 @@ This Layotto state SDK client demo requires you to have the following installed
- A Kubernetes cluster, such as [Minikube](https://minikube.sigs.k8s.io/docs/start/), [Kind](https://kind.sigs.k8s.io/docs/user/quick-start/)
- [Helm v3](https://helm.sh/docs/intro/install/)

# Step 1 - Setup Layotto sidecar injector and Redis on your Kubernetes cluster
# Step 1 - Setup Layotto sidecar injector on your Kubernetes cluster
1. Use Kind to quickly build a local Kubernetes cluster
```
kind create cluster --name layotto-cluster
kubectl config use-context kind-layotto-cluster
```
2. Add xiaoxiang10086.github.io as an helm repo
2. Install the layotto sidecar injector chart on your cluster in the layotto-system namespace
```
helm repo add layotto https://xiaoxiang10086.github.io/layotto-helm-charts/
helm repo update
```
3. Install the Layotto chart on your cluster in the Layotto-system namespace
```
helm install layotto layotto/layotto-sidecar-injector --namespace layotto-system --wait
helm install injector oci://docker.io/layotto/injector-helm --version v0.5.0 -n layotto-system --create-namespace --wait
```

# Step 2 - Use Helm to deploy Redis on your Kubernetes cluster
Expand Down
5 changes: 5 additions & 0 deletions demo/state/k8s/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"context"
"flag"
"fmt"
"math"
"time"

client "mosn.io/layotto/sdk/go-sdk/client"
)
Expand Down Expand Up @@ -71,6 +73,9 @@ func main() {
// delete state
testDelete(ctx, cli, storeName, key1, keyTostate[key1].Etag)
testDelete(ctx, cli, storeName, key2, keyTostate[key2].Etag)

// prevent program exit
time.Sleep(time.Duration(math.MaxInt))
}

func testGetBulkState(ctx context.Context, cli client.Client, store string, key1 string, key2 string) map[string]*client.BulkStateItem {
Expand Down
2 changes: 1 addition & 1 deletion demo/state/k8s/state-sdk-demo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ spec:
spec:
containers:
- name: layotto-state-sdk-demo
image: docker.io/wyx20000905/layotto-state-sdk-demo
image: docker.io/layotto/state-sdk-demo
volumes:
- name: layotto-config-vol
configMap:
Expand Down
6 changes: 6 additions & 0 deletions deploy/charts/injector-helm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
description: A Helm chart for Layotto Injector Kubernetes
name: injector-helm

version: v0.0.0-latest
appVersion: "latest"
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
# Introduction

This chart deploys the Layotto sidecar injector component on a Kubernetes cluster using the Helm package manager.
This chart deploys the Layotto injector component on a Kubernetes cluster using the Helm package manager.

## Prerequisites

- Helm 3
- Kubernetes cluster

## Installing the Chart
## Source Code
- https://github.com/mosn/layotto

## Install the Chart

Ensure Helm is initialized in your Kubernetes cluster.

For more details on initializing Helm, [read the Helm docs](https://helm.sh/docs/)

1. Add xiaoxiang10086.github.io as an helm repo

You can choose install the helm chart from DockerHub.
```
helm repo add layotto https://xiaoxiang10086.github.io/layotto-helm-charts/
helm repo update
helm install injector oci://docker.io/layotto/injector-helm --version v0.5.0 -n layotto-system --create-namespace --wait
```

2. Install the Layotto chart on your cluster in the Layotto-system namespace:

You can also install from the source code:
```
helm install layotto layotto/layotto-sidecar-injector --namespace layotto-system --wait
make helm-install VERSION="v0.5.0"
```


## Verify installation

Once the chart is installed, verify the Layotto sidecar injector component pods are running in the layotto-system namespace:
Once the chart is installed, verify the Layotto sidecar injector pod is running in the layotto-system namespace:

```
kubectl get pods --namespace layotto-system
Expand All @@ -40,7 +38,7 @@ kubectl get pods --namespace layotto-system
To uninstall/delete the layotto release:

```
helm uninstall layotto -n layotto-system
helm uninstall injector -n layotto-system
```

## Configuration
Expand Down
5 changes: 0 additions & 5 deletions deploy/charts/layotto-sidecar-injector/Chart.yaml

This file was deleted.

11 changes: 2 additions & 9 deletions docker/layotto_injector/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
FROM golang:1.18-alpine AS build-env

WORKDIR /app

COPY . .
FROM alpine:latest

RUN go build -o injector cmd/layotto_injector/main.go
COPY ./layotto_injector /injector

FROM alpine:latest
RUN apk --no-cache add ca-certificates
COPY --from=build-env /app/injector .
EXPOSE 8443
4 changes: 4 additions & 0 deletions make/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ endif
ifeq ($(origin K8S_DIR),undefined)
K8S_DIR := $(DEPLOY_DIR)/k8s
endif
ifeq ($(origin CHART_DIR),undefined)
CHART_DIR := $(DEPLOY_DIR)/charts
endif

# set the version number. you should not need to do this
# for the majority of scenarios.
Expand Down Expand Up @@ -130,6 +133,7 @@ include make/golang.mk
include make/image.mk
include make/proto.mk
include make/deploy.mk
include make/helm.mk
include make/wasm.mk
include make/ci.mk
include make/help.mk
66 changes: 66 additions & 0 deletions make/helm.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Copyright 2021 Layotto Authors
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

##@ Helm Development

OCI_REGISTRY ?= oci://docker.io/layotto
CHART_NAME ?= injector-helm
CHART_VERSION ?= ${VERSION}
APP_VERSION ?= ${VERSION}

# ==============================================================================
# Public Commands:
# ==============================================================================

.PHONY: helm-package
helm-package: ## Package layotto injector helm chart.
helm-package: helm.package

.PHONY: helm-push
helm-push: ## Push layotto injector helm chart to OCI registry.
helm-push: helm.push

.PHONY: helm-install
helm-install: ## Install layotto injector helm chart from OCI registry.
helm-install: helm.install

.PHONY: helm-uninstall
helm-uninstall: ## Uninstall layotto injector helm chart.
helm-uninstall: helm.uninstall

# ==============================================================================
# Private Commands:
# ==============================================================================

.PHONY: helm.package
helm.package:
@echo "===========> Package layotto injector helm chart $(CHART_VERSION)"
helm package $(CHART_DIR)/${CHART_NAME} --app-version ${APP_VERSION} --version ${CHART_VERSION} --destination ${OUTPUT_DIR}/charts/

.PHONY: helm.push
helm.push:
@echo "===========> Push layotto injector helm chart $(CHART_VERSION) to OCI registry"
helm push ${OUTPUT_DIR}/charts/${CHART_NAME}-${CHART_VERSION}.tgz ${OCI_REGISTRY}

.PHONY: helm.install
helm.install:
@echo "===========> Install layotto injector helm chart $(CHART_VERSION) from OCI registry"
helm install injector ${OCI_REGISTRY}/${CHART_NAME} --version ${CHART_VERSION} -n layotto-system --create-namespace

.PHONY: helm.uninstall
helm.uninstall:
@echo "===========> Uninstall layotto injector helm chart $(CHART_VERSION)"
helm uninstall injector -n layotto-system



3 changes: 2 additions & 1 deletion make/help.mk
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ $(BOLD_COLOR)Options$(NO_COLOR):
$(GREEN_COLOR)* make deploy-k8s NAMESPACE="layotto"$(NO_COLOR)
$(GREEN_COLOR)* make undeploy-k8s NAMESPACE="default"$(NO_COLOR)
$(BLUE_COLOR)VERSION$(NO_COLOR) The image tag version to build. Default is the latest release tag.
This option is available when using: make image/image-multiarch/push/push-multiarch
This option is available when using: make image/image-multiarch/push/push-multiarch/helm-package/helm-push
Examples:
$(GREEN_COLOR)* make image VERSION="latest"$(NO_COLOR)
$(GREEN_COLOR)* make image-multiarch VERSION="v1.0.0"$(NO_COLOR)
$(GREEN_COLOR)* make push-multiarch VERSION="v2.0.0"$(NO_COLOR)
$(GREEN_COLOR)* make helm-push VERSION="v0.5.0"$(NO_COLOR)
$(BLUE_COLOR)REGISTRY_PREFIX$(NO_COLOR) The docker image registry repo name to push. Default is `layotto`.
This option is available when using: make push/push-multiarch
Examples:
Expand Down