Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenFaas #15

Open
kwojcicki opened this issue Jul 26, 2019 · 0 comments
Open

OpenFaas #15

kwojcicki opened this issue Jul 26, 2019 · 0 comments

Comments

@kwojcicki
Copy link
Owner

kwojcicki commented Jul 26, 2019

Pre reqs

Docker

https://docs.docker.com/install/linux/docker-ce/ubuntu/

faas-cli/faas

curl -sSL https://cli.openfaas.com | sudo sh

helm

sudo snap install helm --classic

DinD, Docker in Docker (https://github.com/kubernetes-sigs/kubeadm-dind-cluster/blob/master/dind-cluster.sh) One can look into KinD Kubernetes in Docker kubernetes-retired/kubeadm-dind-cluster#310

$ wget https://github.com/kubernetes-sigs/kubeadm-dind-cluster/releases/download/v0.2.0/dind-cluster-v1.14.sh
$ chmod +x dind-cluster-v1.14.sh

Starting k8s cluster

export DOWNLOAD_KUBECTL="non_empty"
export DIND_HTTP_PROXY=$http_proxy
export DIND_HTTPS_PROXY=$https_proxy
export DIND_NO_PROXY=$no_proxy
./dind-cluster-v1.14.sh up
export PATH="$HOME/.kubeadm-dind-cluster:$PATH"

OpenFaas install

kubectl -n kube-system create sa tiller && kubectl create clusterrolebinding tiller --clusterrole cluster-admin --serviceaccount=kube-system:tiller

helm init --skip-refresh --upgrade --service-account tiller

kubectl apply -f https://raw.githubusercontent.com/openfaas/faas-netes/master/namespaces.yml

helm repo add openfaas https://openfaas.github.io/faas-netes/

helm repo update

kubectl -n openfaas create secret generic basic-auth --from-literal=basic-auth-user=admin --from-literal=basic-auth-password="password"

sleep 20 # waiting for tiller pod to be ready if command below complains about tiller pod not being ready, wait another 10 seconds

helm upgrade openfaas --install openfaas/openfaas --namespace openfaas --set functionNamespace=openfaas-fn --set basic_auth=true --set faasnetes.imagePullPolicy=IfNotPresent

Visiting OpenFaas UI

export ip=$(docker inspect kube-master -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}')

Visit $ip:31112 with username: admin, password: password

Creating OpenFaas functions

export NO_PROXY=$ip
export no_proxy=$ip
mkdir -p ~/workspace/faas
cd ~/workspace/faas
faas login --username admin --password password --gateway $ip:31112
faas new --lang python3 helloworld
# edit handler.py as you please
faas build -f helloworld.yml
docker save helloworld:latest | docker exec -i kube-node-1 docker load
docker save helloworld:latest | docker exec -i kube-node-2 docker load
faas deploy -f helloworld.yml --gateway $ip:31112

Visit UI to invoke your function or try out the faas invoke command.

Kafka k8s cluster (3zk + 3 kafka) + testpod for executing commands

helm repo add incubator http://storage.googleapis.com/kubernetes-charts-incubator

kubectl create ns kafka

helm upgrade kf incubator/kafka \
    --install \
    --namespace kafka \
    --set imageTag=4.1.3 \
    --set persistence.enabled=false

# kubectl -n kafka apply -f kafka-testing/yaml/test-pod.yml

helm upgrade kafka-connector . \
    --install \
    --namespace openfaas \
    --set broker_host=kf-kafka.kafka

kubectl -n kafka apply -f - <<EOF
apiVersion: v1
kind: Pod
metadata:
  name: testclient
  namespace: kafka
spec:
  containers:
  - name: kafka
    image: confluentinc/cp-kafka:5.0.1
    command:
    - sh
    - -c
    - "exec tail -f /dev/null"
EOF

Misc commands

kubectl get po -o wide -A ### get all pods
kubectl logs xxxxx -n yyyy ### get xxx pods logs in namespace yyy
kubectl describe pod xxxx -n yyyy ### describe pod xxx in namespace yyy

Consuming messages from topic: faas-request-test

kubectl -n kafka exec -it testclient -- kafka-console-consumer --bootstrap-server kf-kafka:9092 --topic faas-request-test --from-beginning

Listing topics

kubectl -n kafka exec testclient -- kafka-topics --zookeeper kf-zookeeper:2181 --list

Creating topics

kubectl -n kafka exec testclient -- kafka-topics --zookeeper kf-zookeeper:2181 --topic test1 --create --partitions 1 --replication-factor 1

Starting an interactive message producer session:

kubectl -n kafka exec -ti testclient -- kafka-console-producer --broker-list kf-kafka-headless:9092 --topic test1

To create a message in the above session, simply type the message and press "enter"

To end the producer session try: Ctrl+C

kubectl logs -n openfaas deploy/kafka-connector -f
kubectl get deployment kafka-connector -n openfaas -o yaml
kubectl port-forward svc/gateway -n openfaas 8080:8080

Lists all containers inside of pods

kubectl get pods --all-namespaces -o jsonpath="{..image}" |tr -s '[[:space:]]' '\n' |sort |uniq -c

Loading docker image into a target node (useful for DinD, KinD has a CLI command that does this for you)

docker save {your_image} | docker exec -i {target_node} docker load

Misc Links

https://github.com/openfaas/faas-netes/blob/master/chart/kafka-connector/development.md
https://github.com/s8sg/faas-flow workflow/function composition

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant