Sajeetharan Sinnathurai
AKS workshop,Colombo 2019 | www.sajeetharan.com
and we need only 30 steps to go there!
Event Driven
Stateless
Microservices
👍 Reduce time-to-market
👍 Easier deployment
👍 Scale automatically
👍 Focus on business logic
👍$$$ Reduction
👍 Stateless
👍 Short Job
👍 Event-driven stuff, e.g. Time-based / webhook
👍 Simple application with less dependency
Kubernetes is a portable, extensible open-source platform for managing containerized workloads and services, that facilitates both declarative configuration and automation
Short Lived
No ports
No states
Serves single purpose
Azure Subscription
Docker installed locally and a docker hub account
Python installed locally
Access to guideliness
Step 1: Launch Azure Cloud shell or Install Azure CLI
Step 2: Run the login command or login https://aka.ms/devicelogin
az login -u <username> -p <password>
Step 3: Create a resource group
az group create --name aksColomboRG --location eastus
Step 4: Create AKS cluster
az aks create --resource-group aksColomboRG --name openFaasCluster --node-vm-size Standard_A2_v2 --node-count 1 --enable-addons monitoring --generate-ssh-keys
Step 6: Connect to the cluster
Step 7: List the cluster nodes
az aks get-credentials --resource-group aksColomboRG --name openFaasCluster --admin -a --overwrite-existing
kubectl get all -n kube-system
Step 8: Install and Init Helm
Step 9: Install OpenFaas
Step 10: Create namespace OpenFaas
Step 11: Create second namespace for OpenFass Functions
Step 12 : Check you have a tiller pod in ready state
helm init --upgrade
git clone https://github.com/openfaas/faas-netes
kubectl create ns openfaaskubectl
kubectl create ns openfaas-fn
kubectl -n kube-system get po
Step 13: Manually start the tiller
Step 14: Resolve cannot list configmaps in the "kube-s"
kubectl create serviceaccount --namespace kube-system tiller
kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller
kubectl patch deploy --namespace kube-system tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}'
helm init --service-account tiller --upgrade
kubectl logs --namespace kube-system tiller-deploy-66cdfd5bc9-46sxv
Step 16: A Helm chart for OpenFaaS is included in the cloned repository. Use this chart to deploy OpenFaaS into your AKS cluster.
helm upgrade --install --namespace openfaas --set functionNamespace=openfaas-fn --set async=true --set serviceType=LoadBalancer openfaas openfaas/openfaas
Step 17: See OpenFaas live
kubectl get all -n openfaas
helm repo add openfaas https://openfaas.github.io/faas-netes/
Step 2: Install faas-cli
Step 3: Login to docker hub
docker login
Step 1: Run Docker Desktop
To install the faas-cli on Windows go to Releases and download the latest faas-cli.exe.
set OPENFAAS_URL=http://23.101.130.111:8080
Step 4: set OpenFaas url
Step 6: List the functions
faas-cli list
Step 7: Remove the function
faas-cli rm -f AKSdemo.yml
faas-cli up -f helloaks.yml
Step 6: Deploy the function
// Create Folder functions
mkdir functions
//Create new function named helloAKS
faas-cli new --lang=node --prefix=sajeetharan helloaks
Step 5: Create first function
Step 2: Get the twitter app for you
Step 3: Add the environment variables
provider:
name: faas
gateway: http://23.101.130.111:8080
functions:
tweetme:
lang: python
handler: ./tweetme
image: sajeetharan/tweetme:latest
environment:
consumer_key: "fdsr43eegegsdvsdfewfrewrewr"
consumer_secret: "wefdsfsdtrewtgdsgds"
access_token: "146725639-f"
access_token_secret: "fsdfsfdffds"
Step 1: Create the function
faas-cli new --lang=python --prefix=sajeetharan tweetme
Step 6: Deploy the app
Step 4: Add dependency in the requirements.txt
tweepy
faas-cli up -f tweetme.yml
Step 5: handler.py
import os
import tweepy
def get_api(cfg):
auth = tweepy.OAuthHandler(cfg['consumer_key'], cfg['consumer_secret'])
auth.set_access_token(cfg['access_token'], cfg['access_token_secret'])
return tweepy.API(auth)
def handle(tweet):
cfg = {
"consumer_key" : os.environ['consumer_key'],
"consumer_secret" : os.environ['consumer_secret'],
"access_token" : os.environ['access_token'],
"access_token_secret" : os.environ['access_token_secret']
}
api = get_api(cfg)
status = api.update_status(status=tweet)
print('Tweet sent.')
print(status)