From 67230a934d2863d59da7540e2c937974a18f7549 Mon Sep 17 00:00:00 2001 From: Le Yao <54387247+leyao-daily@users.noreply.github.com> Date: Wed, 15 Dec 2021 02:23:07 +0000 Subject: [PATCH] Create helm chart for cnf and crd controller Create helm chart for CNF and CRD controller. Add example configuration file for deployment. Guide to deploy the helm. Signed-off-by: Le Yao Change-Id: I3982a4c17ed5f1d4fa00de865fefdda83f2a7470 --- platform/deployment/README.md | 93 ++ platform/deployment/examples/README.md | 23 + platform/deployment/examples/cnfservice.yaml | 11 + platform/deployment/examples/nginx-dp-svc.yaml | 42 + platform/deployment/helm/cert/cnf_cert.yaml | 49 + platform/deployment/helm/sdewan_cnf/Chart.yaml | 21 + .../helm/sdewan_cnf/templates/_helpers.tpl | 63 + .../deployment/helm/sdewan_cnf/templates/cm.yaml | 97 ++ .../helm/sdewan_cnf/templates/deployment.yaml | 111 ++ .../helm/sdewan_cnf/templates/secret.yaml | 24 + platform/deployment/helm/sdewan_cnf/values.yaml | 59 + .../deployment/helm/sdewan_controllers/.helmignore | 23 + .../deployment/helm/sdewan_controllers/Chart.yaml | 21 + .../helm/sdewan_controllers/templates/_helpers.tpl | 63 + .../sdewan_controllers/templates/certificate.yaml | 17 + .../helm/sdewan_controllers/templates/crd.yaml | 1342 ++++++++++++++++++++ .../sdewan_controllers/templates/deployment.yaml | 62 + .../helm/sdewan_controllers/templates/issuer.yaml | 12 + .../helm/sdewan_controllers/templates/role.yaml | 429 +++++++ .../helm/sdewan_controllers/templates/service.yaml | 30 + .../helm/sdewan_controllers/templates/webhook.yaml | 74 ++ .../deployment/helm/sdewan_controllers/values.yaml | 19 + 22 files changed, 2685 insertions(+) create mode 100644 platform/deployment/README.md create mode 100644 platform/deployment/examples/README.md create mode 100644 platform/deployment/examples/cnfservice.yaml create mode 100644 platform/deployment/examples/nginx-dp-svc.yaml create mode 100644 platform/deployment/helm/cert/cnf_cert.yaml create mode 100644 platform/deployment/helm/sdewan_cnf/Chart.yaml create mode 100644 platform/deployment/helm/sdewan_cnf/templates/_helpers.tpl create mode 100644 platform/deployment/helm/sdewan_cnf/templates/cm.yaml create mode 100644 platform/deployment/helm/sdewan_cnf/templates/deployment.yaml create mode 100644 platform/deployment/helm/sdewan_cnf/templates/secret.yaml create mode 100644 platform/deployment/helm/sdewan_cnf/values.yaml create mode 100644 platform/deployment/helm/sdewan_controllers/.helmignore create mode 100644 platform/deployment/helm/sdewan_controllers/Chart.yaml create mode 100644 platform/deployment/helm/sdewan_controllers/templates/_helpers.tpl create mode 100644 platform/deployment/helm/sdewan_controllers/templates/certificate.yaml create mode 100644 platform/deployment/helm/sdewan_controllers/templates/crd.yaml create mode 100644 platform/deployment/helm/sdewan_controllers/templates/deployment.yaml create mode 100644 platform/deployment/helm/sdewan_controllers/templates/issuer.yaml create mode 100644 platform/deployment/helm/sdewan_controllers/templates/role.yaml create mode 100644 platform/deployment/helm/sdewan_controllers/templates/service.yaml create mode 100644 platform/deployment/helm/sdewan_controllers/templates/webhook.yaml create mode 100644 platform/deployment/helm/sdewan_controllers/values.yaml diff --git a/platform/deployment/README.md b/platform/deployment/README.md new file mode 100644 index 0000000..b3556a7 --- /dev/null +++ b/platform/deployment/README.md @@ -0,0 +1,93 @@ +# Helm Chart for cnf and controller + +## Pre-condition +**1.Install cert-manager** + +`kubectl apply -f https://github.com/jetstack/cert-manager/releases/download/v1.1.0/cert-manager.yaml` + +**2.Label the node** + +``` +nodename=$(kubectl get node -o jsonpath='{.items[0].metadata.name}') +kubectl taint node $nodename node-role.kubernetes.io/master:NoSchedule- +kubectl label --overwrite node $nodename ovn4nfv-k8s-plugin=ovn-control-plane +``` + +**3.Install network** + +For the network configuration, the helm charts of CNF and Controller need integrate Multus CNI with Calico as default network and icn-nodus. So you can refer to the [guide](https://github.com/akraino-edge-stack/icn-nodus/blob/master/doc/how-to-use.md#testing-with-cni-proxy) to setup your environment. + +**4.Apply provide network** + +- Create ovn-network and provider-network, e.g. +``` +--- +apiVersion: k8s.plugin.opnfv.org/v1alpha1 +kind: ProviderNetwork +metadata: + name: pnetwork +spec: + cniType: ovn4nfv + ipv4Subnets: + - subnet: 10.10.20.1/24 + name: subnet + gateway: 10.10.20.1/24 + excludeIps: 10.10.20.2..10.10.20.9 + providerNetType: VLAN + vlan: + logicalInterfaceName: eno1.100 // Change to your interface name + providerInterfaceName: eno1 + vlanId: "100" + vlanNodeSelector: all + +--- +apiVersion: k8s.plugin.opnfv.org/v1alpha1 +kind: Network +metadata: + name: ovn-network +spec: + # Add fields here + cniType: ovn4nfv + ipv4Subnets: + - subnet: 172.16.30.1/24 + name: subnet1 + gateway: 172.16.30.1/24 +``` +- Update `helm/sdewan_cnf/values.yaml` to configure the network information + +**5.Install helm** + +``` +curl https://baltocdn.com/helm/signing.asc | sudo apt-key add - +sudo apt-get install apt-transport-https --yes +echo "deb https://baltocdn.com/helm/stable/debian/ all main" | sudo tee /etc/apt/sources.list.d/helm-stable-debian.list +sudo apt-get update +sudo apt-get install helm +``` + +## Steps to install CNF and CRD Controller + +Please locate your directory to `./helm`. + +**1.Create namespace for SDEWAN Central Controller v1Microservices** + +`kubectl create namespace sdewan-system` + +**2.Generate certificate for cnf** + +`kubectl apply -f cert/cnf_cert.yaml` + +**3.Install CNF** + +``` +helm package sdewan_cnf +helm install ./cnf-0.1.0.tgz --generate-name +``` + +**4.Install CRD controller** + +``` +helm package sdewan_controllers +helm install ./controllers-0.1.0.tgz --generate-name +``` + diff --git a/platform/deployment/examples/README.md b/platform/deployment/examples/README.md new file mode 100644 index 0000000..09f3aab --- /dev/null +++ b/platform/deployment/examples/README.md @@ -0,0 +1,23 @@ +# Example to verify +This is an example which you can test your SDEWAN deployment environment. + +## Pre-condition +**1.Install a simple nginx deployment and service** + +`kubectl apply -f nginx-dp-svc.yaml` + +**2.Apply the cnf service CR** + +`kubectl apply -f cnfservice.yaml` + +**3.Verify** + +``` +# From host, you can get the nginx response from cnf +curl :8866 + +# login to the cnf pod and see the iptables +kubectl exec -ti -n -- sudo bash +iptable -L -t nat +# DNAT tcp -- anywhere anywhere tcp dpt:8866 to::80 +``` diff --git a/platform/deployment/examples/cnfservice.yaml b/platform/deployment/examples/cnfservice.yaml new file mode 100644 index 0000000..e2671a4 --- /dev/null +++ b/platform/deployment/examples/cnfservice.yaml @@ -0,0 +1,11 @@ +apiVersion: batch.sdewan.akraino.org/v1alpha1 +kind: CNFService +metadata: + name: cnfservice-sample + labels: + sdewanPurpose: sdewan-safe +spec: + fullname: nginx.default.svc.cluster.local + port: "8866" + dport: "80" + diff --git a/platform/deployment/examples/nginx-dp-svc.yaml b/platform/deployment/examples/nginx-dp-svc.yaml new file mode 100644 index 0000000..5368920 --- /dev/null +++ b/platform/deployment/examples/nginx-dp-svc.yaml @@ -0,0 +1,42 @@ +--- +apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2 +kind: Deployment +metadata: + name: nginx +spec: + strategy: + type: Recreate + selector: + matchLabels: + app: nginx + replicas: 3 + template: # create pods using pod definition in this template + metadata: + labels: + app: nginx + spec: + containers: + - name: nginx + image: nginx + ports: + - containerPort: 80 +--- +apiVersion: v1 +kind: Service +metadata: + name: nginx + namespace: default + labels: + app: nginx + annotations: + service.beta.kubernetes.io/aws-load-balancer-type: "nlb" +spec: + externalTrafficPolicy: Local + ports: + - name: http + port: 80 + protocol: TCP + targetPort: 80 + selector: + app: nginx + type: LoadBalancer diff --git a/platform/deployment/helm/cert/cnf_cert.yaml b/platform/deployment/helm/cert/cnf_cert.yaml new file mode 100644 index 0000000..dc9924f --- /dev/null +++ b/platform/deployment/helm/cert/cnf_cert.yaml @@ -0,0 +1,49 @@ +apiVersion: cert-manager.io/v1 +kind: ClusterIssuer +metadata: + name: cnf-root-issuer +spec: + selfSigned: {} + +--- +apiVersion: cert-manager.io/v1 +kind: Certificate +metadata: + name: cnf-root-cert + namespace: default +spec: + commonName: "sdwan" + duration: 17520h + isCA: true + issuerRef: + kind: ClusterIssuer + name: cnf-root-issuer + secretName: cnf-root-cert + +--- +apiVersion: cert-manager.io/v1 +kind: Issuer +metadata: + name: cnf-default-issuer + namespace: default +spec: + ca: + secretName: cnf-root-cert + +--- +apiVersion: cert-manager.io/v1 +kind: Certificate +metadata: + name: cnf-default-cert + namespace: default +spec: + commonName: "*.default.pod.cluster.local" + duration: 17520h + isCA: false + issuerRef: + kind: Issuer + name: cnf-default-issuer + secretName: cnf-default-cert + commonName: "*.default.pod.cluster.local" + dnsNames: + - "*.default.pod.cluster.local" diff --git a/platform/deployment/helm/sdewan_cnf/Chart.yaml b/platform/deployment/helm/sdewan_cnf/Chart.yaml new file mode 100644 index 0000000..a28022a --- /dev/null +++ b/platform/deployment/helm/sdewan_cnf/Chart.yaml @@ -0,0 +1,21 @@ +#/* +# * Copyright (c) 2021 Intel Corporation, Inc +# * +# * 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. +# */ + +apiVersion: v1 +name: cnf +description: A Helm chart for Kubernetes +version: 0.1.0 +appVersion: "1.0" diff --git a/platform/deployment/helm/sdewan_cnf/templates/_helpers.tpl b/platform/deployment/helm/sdewan_cnf/templates/_helpers.tpl new file mode 100644 index 0000000..e83bd22 --- /dev/null +++ b/platform/deployment/helm/sdewan_cnf/templates/_helpers.tpl @@ -0,0 +1,63 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "cnf.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "cnf.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "cnf.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "cnf.labels" -}} +helm.sh/chart: {{ include "cnf.chart" . }} +{{ include "cnf.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "cnf.selectorLabels" -}} +app.kubernetes.io/name: {{ include "cnf.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "cnf.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "cnf.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/platform/deployment/helm/sdewan_cnf/templates/cm.yaml b/platform/deployment/helm/sdewan_cnf/templates/cm.yaml new file mode 100644 index 0000000..15e15aa --- /dev/null +++ b/platform/deployment/helm/sdewan_cnf/templates/cm.yaml @@ -0,0 +1,97 @@ +#/* Copyright (c) 2021 Intel Corporation, Inc +# * +# * 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. +# */ + +apiVersion: v1 +data: + entrypoint.sh: |- + #!/bin/bash + # Always exit on errors. + set -ex + echo "" > /etc/config/network + cat > /etc/config/mwan3 <> /etc/config/network <