diff --git a/deploy/docker_registry_setup.sh b/deploy/docker_registry_setup.sh deleted file mode 100644 index b38a1ab..0000000 --- a/deploy/docker_registry_setup.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -IP=$1 -sed "/ExecStart/ s/$/ --insecure-registry=$IP/" /lib/systemd/system/docker.service > /lib/systemd/system/tmp -mv /lib/systemd/system/tmp /lib/systemd/system/docker.service -systemctl daemon-reload -systemctl restart docker.service -docker run -d -p 5000:5000 --restart=always --name registry registry:2 diff --git a/deploy/install_riff.sh b/deploy/install_riff.sh deleted file mode 100644 index d903a7d..0000000 --- a/deploy/install_riff.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -#Install riff cli -curl -Lo riff-linux-amd64.tgz https://github.com/projectriff/cli/releases/download/v0.4.0/riff-linux-amd64.tgz -tar xvzf riff-linux-amd64.tgz -mv riff /usr/local/bin/ - -#Install riff -helm repo add projectriff https://projectriff.storage.googleapis.com/charts/releases -helm repo update - -helm install projectriff/istio --name istio --version 0.4.x --namespace istio-system --set gateways.istio-ingressgateway.type=NodePort --wait -helm install projectriff/riff --name riff --version 0.4.x --set knative.enabled=true - -#Verify Install -riff doctor diff --git a/deploy/kubeless_setup.sh b/deploy/kubeless_setup.sh new file mode 100644 index 0000000..43943d0 --- /dev/null +++ b/deploy/kubeless_setup.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +git clone https://github.com/kubernetes-incubator/metrics-server.git +sed -i '34i\ command:\' metrics-server/deploy/1.8+/metrics-server-deployment.yaml +sed -i '35i\ - /metrics-server\' metrics-server/deploy/1.8+/metrics-server-deployment.yaml +sed -i '36i\ - --kubelet-insecure-tls\' metrics-server/deploy/1.8+/metrics-server-deployment.yaml +kubectl create -f metrics-server/deploy/1.8+/ + +RELEASE=$(curl -s https://api.github.com/repos/kubeless/kubeless/releases/latest | grep tag_name | cut -d '"' -f 4) +kubectl create ns kubeless +kubectl create -f https://github.com/kubeless/kubeless/releases/download/$RELEASE/kubeless-$RELEASE.yaml +#kubectl create -f https://github.com/kubeless/kubeless/releases/download/$RELEASE/kubeless-non-rbac-$RELEASE.yaml + +apt install -y unzip + +#kubeless command +OS=$(uname -s| tr '[:upper:]' '[:lower:]') +curl -OL https://github.com/kubeless/kubeless/releases/download/$RELEASE/kubeless_$OS-amd64.zip && \ + unzip kubeless_$OS-amd64.zip && \ + sudo mv bundles/kubeless_$OS-amd64/kubeless /usr/local/bin/ + +#Ingress nginx +kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/mandatory.yaml +kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/provider/baremetal/service-nodeport.yaml diff --git a/deploy/kubernetes_dashboard_setup.sh b/deploy/kubernetes_dashboard_setup.sh deleted file mode 100644 index 4f92455..0000000 --- a/deploy/kubernetes_dashboard_setup.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash - -#Gen certificates -mkdir -p certs -cd certs -CERT_DIR=$PWD -openssl genrsa -des3 -passout pass:x -out dashboard.pass.key 2048 -openssl rsa -passin pass:x -in dashboard.pass.key -out dashboard.key -rm dashboard.pass.key -openssl req -new -key dashboard.key -out dashboard.csr -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com" -openssl x509 -req -sha256 -days 365 -in dashboard.csr -signkey dashboard.key -out dashboard.crt -kubectl create secret generic kubernetes-dashboard-certs --from-file=$CERT_DIR -n kube-system -cd .. - -#Deploy the dashboard -#wget https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml -wget https://raw.githubusercontent.com/kubernetes/dashboard/master/aio/deploy/recommended/kubernetes-dashboard.yaml -sed -i '176i\ type: LoadBalancer' kubernetes-dashboard.yaml -kubectl apply -f kubernetes-dashboard.yaml - -#Token based dashboard authentication -kubectl create serviceaccount k8sadmin -n kube-system -kubectl create clusterrolebinding k8sadmin --clusterrole=cluster-admin --serviceaccount=kube-system:k8sadmin diff --git a/functions/kubeless/Gopkg.toml b/functions/kubeless/Gopkg.toml new file mode 100644 index 0000000..2c26088 --- /dev/null +++ b/functions/kubeless/Gopkg.toml @@ -0,0 +1,5 @@ +ignored = ["github.com/kubeless/kubeless/pkg/functions"] + +[[constraint]] + name = "github.com/sirupsen/logrus" +branch = "master" diff --git a/functions/kubeless/deploy_function.sh b/functions/kubeless/deploy_function.sh new file mode 100644 index 0000000..a644210 --- /dev/null +++ b/functions/kubeless/deploy_function.sh @@ -0,0 +1,11 @@ +#!/bin/bash +#$1=runtime +#$2=filename +#$3=function name +#$4=handler + +kubeless function deploy $3 --runtime $1 --from-file $2 --handler $4 +kubeless trigger http create $3 --function-name $3 --path $3 --hostname $3.kubeless +#kubeless autoscale create $3 --max 32 --metric "cpu" --min 3 --value "50" + +#Test with curl --data '{"Another": "Echo"}' --header "Host: get-python.192.168.99.100.nip.io" --header "Content-Type:application/json" 192.168.99.100/echo diff --git a/functions/kubeless/helloget.go b/functions/kubeless/helloget.go new file mode 100644 index 0000000..04cd38a --- /dev/null +++ b/functions/kubeless/helloget.go @@ -0,0 +1,10 @@ +package kubeless + +import ( + "github.com/kubeless/kubeless/pkg/functions" +) + +// Foo sample function +func Foo(event functions.Event, context functions.Context) (string, error) { + return "Hello world!", nil +} \ No newline at end of file diff --git a/functions/kubeless/helloget.js b/functions/kubeless/helloget.js new file mode 100644 index 0000000..c694c22 --- /dev/null +++ b/functions/kubeless/helloget.js @@ -0,0 +1,5 @@ +module.exports = { + foo: function (event, context) { + return 'hello world!'; + } +} diff --git a/functions/kubeless/helloget.py b/functions/kubeless/helloget.py new file mode 100644 index 0000000..594c6e3 --- /dev/null +++ b/functions/kubeless/helloget.py @@ -0,0 +1,2 @@ +def foo(event, context): +return "hello world" diff --git a/functions/kubeless/isprime.go b/functions/kubeless/isprime.go new file mode 100644 index 0000000..9660cf9 --- /dev/null +++ b/functions/kubeless/isprime.go @@ -0,0 +1,27 @@ +package kubeless + +import ( + "fmt" + "math" + "strconv" + + "github.com/kubeless/kubeless/pkg/functions" + "github.com/sirupsen/logrus" +) + +func IsPrime(event functions.Event, context functions.Context) (string, error) { + num, err := strconv.Atoi(event.Data) + if err != nil { + return "", fmt.Errorf("Failed to parse %s as int! %v", event.Data, err) + } + logrus.Infof("Checking if %s is prime", event.Data) + if num <= 1 { + return fmt.Sprintf("%d is not prime", num), nil + } + for i := 2; i <= int(math.Floor(float64(num)/2)); i++ { + if num%i == 0 { + return fmt.Sprintf("%d is not prime", num), nil + } + } + return fmt.Sprintf("%d is prime", num), nil +} diff --git a/functions/kubeless/isprime.js b/functions/kubeless/isprime.js new file mode 100644 index 0000000..b43e5bc --- /dev/null +++ b/functions/kubeless/isprime.js @@ -0,0 +1,26 @@ +module.exports = { + handler: (event, context) => { + num=event.data; + if (num == 1) return "Not Prime"; + num += 2; + + var upper = Math.sqrt(num); + var sieve = new Array(num) + .join(',').split(',') // get values for map to work + .map(function(){ return "Prime" }); + + for (var i = 2; i <= num; i++) { + if (sieve[i]) { + for (var j = i * i; j < num; j += i) { + sieve[j] = false; + }; + }; + }; +if (sieve[num-2]) { + return "Prime"; + }; + else { + return "Not Prime"; +}; + }, +}; diff --git a/functions/kubeless/isprime.py b/functions/kubeless/isprime.py new file mode 100644 index 0000000..9bde86d --- /dev/null +++ b/functions/kubeless/isprime.py @@ -0,0 +1,13 @@ +def isprime(event,context): + n= event['data'] + if n == 2 or n == 3: return "Prime" + if n < 2 or n%2 == 0: return "Not Prime" + if n < 9: return "Prime" + if n%3 == 0: return "Not Prime" + r = int(n**0.5) + f = 5 + while f <= r: + if n%f == 0: return "Not Prime" + if n%(f+2) == 0: return "Not Prime" + f +=6 + return "Prime" diff --git a/functions/kubeless/matrix.go b/functions/kubeless/matrix.go new file mode 100644 index 0000000..9cc6bf6 --- /dev/null +++ b/functions/kubeless/matrix.go @@ -0,0 +1,70 @@ +package kubeless + +import ( + "fmt" + + "github.com/kubeless/kubeless/pkg/functions" +) +func main() { + //Defining 2D matrices + m1 := [3][3]int{ + [3]int{1, 1, 1}, + [3]int{1, 1, 1}, + [3]int{1, 1, 1}, + } + m2 := [3][3]int{ + [3]int{1, 1, 1}, + [3]int{1, 1, 1}, + [3]int{1, 1, 1}, + } + + //Declaring a matrix variable for holding the multiplication results + var m3 [3][3]int + + for i := 0; i < 3; i++ { + for j := 0; j < 3; j++ { + m3[i][j] = 0 + for k := 0; k < 3; k++ { + m3[i][j] = m3[i][j] + (m1[i][k] * m2[k][j]) + } + } + } + + twoDimensionalMatrices := [3][3][3]int{m1, m2, m3} + + matrixNames := []string{"MATRIX1", "MATRIX2", "MATRIX3 = MATRIX1*MATRIX2"} + for index, m := range twoDimensionalMatrices { + fmt.Println(matrixNames[index],":") + showMatrixElements(m) + fmt.Println() + } +} + +//A function that displays matix elements +func showMatrixElements(m [3][3]int) { + for i := 0; i < 3; i++ { + for j := 0; j < 3; j++ { + fmt.Printf("%d\t", m[i][j]) + } + fmt.Println() + } +} + +/* + +MATRIX1 1 : +1 1 1 +1 1 1 +1 1 1 + +MATRIX2 2 : +1 1 1 +1 1 1 +1 1 1 + +MATRIX3 = MATRIX1*MATRIX2 3 : +3 3 3 +3 3 3 +3 3 3 + +*/