kubeless installers

This commit is contained in:
Torma Kristóf 2019-10-14 21:32:00 +02:00
parent 40a2f5dbe3
commit babc8b83d3
Signed by: tormakris
GPG Key ID: DC83C4F2C41B1047
13 changed files with 193 additions and 46 deletions

View File

@ -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

View File

@ -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

24
deploy/kubeless_setup.sh Normal file
View File

@ -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

View File

@ -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

View File

@ -0,0 +1,5 @@
ignored = ["github.com/kubeless/kubeless/pkg/functions"]
[[constraint]]
name = "github.com/sirupsen/logrus"
branch = "master"

View File

@ -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

View File

@ -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
}

View File

@ -0,0 +1,5 @@
module.exports = {
foo: function (event, context) {
return 'hello world!';
}
}

View File

@ -0,0 +1,2 @@
def foo(event, context):
return "hello world"

View File

@ -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
}

View File

@ -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";
};
},
};

View File

@ -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"

View File

@ -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
*/