O'Reilly logo

Kubernetes for Serverless Applications by Russ McKendrick

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The Twitter function

Now that we have our environment prepared we can deploy the function. To do this we need two files; the first is the requirements.txt file, this contains just two lines:

python-twitterkubernetes==2.0.0

The requirements.txt file lets Python know which external libraries to deploy alongside our code. In our file we are using the twitter library so that we can post the tweet easily, and also the kubernetes library to decode the secrets we created in the previous section. Using the libraries means that our code is quite streamlined, as all of the hard work takes place outside our core function. The code for the function is as follows:

import base64import twitterfrom kubernetes import client, configconfig.load_incluster_config() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required