3 # ============LICENSE_START====================================================
4 # Copyright (C) 2022 Nordix Foundation.
5 # =============================================================================
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
18 # SPDX-License-Identifier: Apache-2.0
19 # ============LICENSE_END======================================================
21 # This script spins up kubernetes cluster in Microk8s for deploying policy helm charts.
23 function spin_microk8s_cluster () {
24 echo "Verify if Microk8s cluster is running.."
28 if [ "$exitcode" -ne 0 ]; then
29 echo "Microk8s cluster not available, Spinning up the cluster.."
30 sudo snap install microk8s --classic --channel=1.25/stable
32 if [ "${?}" -ne 0 ]; then
33 echo "Failed to install kubernetes cluster. Aborting.."
36 echo "Microk8s cluster installed successfully"
37 sudo usermod -a -G microk8s $USER
38 echo "Enabling DNS and helm3"
39 microk8s.enable dns helm3
40 echo "Creating configuration file for Microk8s"
41 microk8s kubectl config view --raw > $HOME/.kube/config
42 chmod 600 $HOME/.kube/config
43 echo "K8s installation completed"
45 echo "K8s cluster is already running"
51 function teardown_cluster () {
52 echo "Removing k8s cluster and k8s configuration file"
53 sudo snap remove microk8s;rm -rf $HOME/.kube/config
54 echo "K8s Cluster removed"
58 if [ $1 == "install" ]; then
60 if [ "${?}" -eq 0 ]; then
61 echo "Installing policy helm charts in the default namespace"
62 cd ../helm/;helm dependency build policy;microk8s helm install dev-policy policy;
63 echo "Policy chart installation completed"
66 elif [ $1 == "uninstall" ]; then
69 echo "Invalid arguments provided. Usage: $0 [option..] {install | uninstall}"