diff --git a/.gitignore b/.gitignore index f7f547adacfd4c8dae8f20c1eead1ffeff5d5e66..55df2b5bde8cc3e0824480a1536db684d9bfd6e6 100644 --- a/.gitignore +++ b/.gitignore @@ -146,3 +146,5 @@ dmypy.json # Cython debug symbols cython_debug/ +# Other +/tmp diff --git a/INSTALL.md b/INSTALL.md new file mode 100644 index 0000000000000000000000000000000000000000..07bdf8f459aa8691e4c7e9d806e3c9d48b8563e5 --- /dev/null +++ b/INSTALL.md @@ -0,0 +1,22 @@ +# TeraFlow OS SDN Controller Installation Instructions +Assuming you have a running Kubernetes deployment installed following the instructions provided in [Wiki: Installing Kubernetes on your Linux machine](../../wikis/Installing-Kubernetes-on-your-Linux-machine), the following instructions will let you deploy TeraFlow OS SDN Controller in your local Kubernetes environment. + +Among others, it is assumed that you can run the command <code> kubectl cluster-info</code> in the machine you use for running the deployment script below. + + +## 1. Clone the repository +Create a folder (e.g., ~/deploy-test/teraflow/controller) to place the source code, move to that folder, clone the repository, and checkout the target branch you want to deploy (e.g., master or develop): + +<code>mkdir -p ~/deploy-test/teraflow/controller; cd ~/deploy-test/teraflow/controller</code> + +<code>git clone https://gitlab.com/teraflow-h2020/controller.git .</code> + +<code>git checkout develop</code> + + +## 2. Adapt deployment script +Find the script <code>deploy_to_kubernetes.sh</code> and modify the configuration settings at the top of the script according to your local Kubernetes environment. + + +## 3. Run the deployment script +Execute the script <code>deploy_to_kubernetes.sh</code> to build and deploy the components at your local Kubernetes environment. diff --git a/README.md b/README.md index 8db25cd48040fa7ecab7b0aba311c4f314673fbf..56d4ee5ca9b2b0f979022f1b8d12d10eaef4ca34 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,10 @@ -# Teraflow SDN controller +# TeraFlow OS SDN Controller [Teraflow H2020 project](https://teraflow-h2020.eu/) - Secured autonomic traffic management for a Tera of SDN Flows Branch "master" : [](https://gitlab.com/teraflow-h2020/controller/-/commits/master) [](https://gitlab.com/teraflow-h2020/controller/-/commits/master) Branch "develop" : [](https://gitlab.com/teraflow-h2020/controller/-/commits/develop) [](https://gitlab.com/teraflow-h2020/controller/-/commits/develop) + +# Installation Instructions +To install TeraFlow OS SDN Controller in your local Kubernetes deployment, we assume you deployed Kubernetes following the instructions provided in [Wiki: Installing Kubernetes on your Linux machine](../../wikis/Installing-Kubernetes-on-your-Linux-machine). Then, follow instructions in [INSTALL.md](./INSTALL.md). diff --git a/deploy_in_kubernetes.sh b/deploy_in_kubernetes.sh new file mode 100755 index 0000000000000000000000000000000000000000..2abfecaf4553c28cfc797d960d94186ce0e63f75 --- /dev/null +++ b/deploy_in_kubernetes.sh @@ -0,0 +1,79 @@ +#!/bin/bash + +######################################################################################################################## +# Define your deployment settings here +######################################################################################################################## + +# Set the URL of your local Docker registry where the images will be uploaded to. Leave it blank if you do not want to +# use any Docker registry. +REGISTRY_IMAGE="" +#REGISTRY_IMAGE="http://my-container-registry.local/" + +# Set the list of components you want to build images for, and deploy. +COMPONENTS="context device service compute monitoring centralizedattackdetector" + +# Set the tag you want to use for your images. +IMAGE_TAG="tf-dev" + +# Set the name of the Kubernetes namespace to deploy to. +K8S_NAMESPACE="tf-dev" + + +######################################################################################################################## +# Automated steps start here +######################################################################################################################## + +# Constants +CLONE_URL="https://gitlab.com/teraflow-h2020/controller.git" +GITLAB_REPO_URL="registry.gitlab.com/teraflow-h2020/controller" +TMP_FOLDER="./tmp" + +# Create a tmp folder for files modified during the deployment +TMP_MANIFESTS_FOLDER="$TMP_FOLDER/manifests" +mkdir -p $TMP_MANIFESTS_FOLDER +TMP_LOGS_FOLDER="$TMP_FOLDER/logs" +mkdir -p $TMP_LOGS_FOLDER + + +# Re-create the namespace to prevent being affected by garbage on it +kubectl delete namespace $K8S_NAMESPACE +kubectl create namespace $K8S_NAMESPACE + +for COMPONENT in $COMPONENTS; do + echo "Processing '$COMPONENT' component..." + IMAGE_NAME="$COMPONENT:$IMAGE_TAG" + IMAGE_URL="$REGISTRY_IMAGE/$IMAGE_NAME" + + echo " Building Docker image..." + BUILD_LOG="$TMP_LOGS_FOLDER/build_${COMPONENT}.log" + docker build -t "$IMAGE_NAME" -f ./src/$COMPONENT/Dockerfile ./src/ > $BUILD_LOG + + if [ -n "$REGISTRY_IMAGE" ]; then + echo "Pushing Docker image to '$REGISTRY_IMAGE'..." + + TAG_LOG="$TMP_LOGS_FOLDER/tag_${COMPONENT}.log" + docker tag "$IMAGE_NAME" "$IMAGE_URL" > $TAG_LOG + + PUSH_LOG="$TMP_LOGS_FOLDER/push_${COMPONENT}.log" + docker push "$IMAGE_URL" > "$PUSH_LOG" + fi + + echo " Adapting manifest file..." + MANIFEST="$TMP_MANIFESTS_FOLDER/${COMPONENT}service.yaml" + cp ./manifests/${COMPONENT}service.yaml $MANIFEST + if [ -n "$REGISTRY_IMAGE" ]; then + sed -E -i "s#image: $GITLAB_REPO_URL/$COMPONENT:latest#image: $IMAGE_URL#g" $MANIFEST + sed -E -i "s#imagePullPolicy: .*#imagePullPolicy: Always#g" $MANIFEST + else + sed -E -i "s#image: $GITLAB_REPO_URL/$COMPONENT:latest#image: $IMAGE_NAME#g" $MANIFEST + sed -E -i "s#imagePullPolicy: .*#imagePullPolicy: Never#g" $MANIFEST + fi + + echo " Deploying to Kubernetes..." + DEPLOY_LOG="$TMP_LOGS_FOLDER/push_${COMPONENT}.log" + kubectl --namespace $K8S_NAMESPACE apply -f $MANIFEST > $DEPLOY_LOG +done + +kubectl --namespace $K8S_NAMESPACE get all + +echo "Done!"