Deploy your first FaaS Application on Knative - Preparation
In a series of posts, I will give a brief introduction on how to host an application on Knative, which is an open source framework of FaaS. If you haven't heard of Knative, maybe you have probably heard AWS Lambda, which is a FaaS product managed by AWS.
First, install envsubst, which is installed by the gettext package. We will use envsubst in later chapters where we substitute parameters especially environment variables and things like that.
To install gettext on CentOS:
$ yum install gettext
MacOS:
$ brew install gettext
Updating Homebrew... ... ==> Downloading https://homebrew.bintray.com/bottles/gettext-0.20.2_1.mojave.bottle.tar.gz ==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/52067198cab528f05fdc0b06f7b9711f7614f60a7361f1e764c4f46d3342ff22?response-conten ######################################################################## 100.0% ==> Pouring gettext-0.20.2_1.mojave.bottle.tar.gz ==> Caveats Emacs Lisp files have been installed to: /usr/local/share/emacs/site-lisp/gettext ==> Summary ???? /usr/local/Cellar/gettext/0.20.2_1: 1,929 files, 18.7MB ==> `brew cleanup` has not been run in 30 days, running now... Removing: /Users/leodu/Library/Caches/Homebrew/aws-iam-authenticator--0.5.0.mojave.bottle.tar.gz... (11.0MB) Removing: /Users/leodu/Library/Caches/Homebrew/aws-sam-cli--0.48.0.sierra.bottle.tar.gz... (11.6MB) Removing: /Users/leodu/Library/Caches/Homebrew/jq--1.6.mojave.bottle.1.tar.gz... (413.5KB) Removing: /Users/leodu/Library/Caches/Homebrew/openssl@1.1--1.1.1g.mojave.bottle.tar.gz... (5.3MB) Removing: /Users/leodu/Library/Caches/Homebrew/python--3.7.7.mojave.bottle.tar.gz... (14.9MB) Removing: /Users/leodu/Library/Caches/Homebrew/readline--8.0.4.mojave.bottle.tar.gz... (517.6KB) Removing: /Users/leodu/Library/Caches/Homebrew/sqlite--3.31.1.mojave.bottle.tar.gz... (1.9MB) Removing: /Users/leodu/Library/Caches/Homebrew/xz--5.2.5.mojave.bottle.tar.gz... (386.8KB) Removing: /Users/leodu/Library/Caches/Homebrew/descriptions.json... (271.9KB) Removing: /Users/leodu/Library/Logs/Homebrew/aws-sam-cli... (64B) Removing: /Users/leodu/Library/Logs/Homebrew/python... (3 files, 148.3KB) Removing: /Users/leodu/Library/Logs/Homebrew/readline... (64B) Removing: /Users/leodu/Library/Logs/Homebrew/sqlite... (64B) Removing: /Users/leodu/Library/Logs/Homebrew/xz... (64B)
Install Google Cloud SDK
Download the file.
$ wget https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-321.0.0-linux-x86_64.tar.gz
Extract the contents of the file.
$ tar -xvf google-cloud-sdk-321.0.0-linux-x86_64.tar.gz
Use the install script to add Cloud SDK tools to your path.
Below command works both on MacOS and Linux.
$ ./google-cloud-sdk/install.sh
Welcome to the Google Cloud SDK! To help improve the quality of this product, we collect anonymized usage data and anonymized stacktraces when crashes are encountered; additional information is available at <https://cloud.google.com/sdk/usage-statistics>. This data is handled in accordance with our privacy policy <https://cloud.google.com/terms/cloud-privacy-notice>. You may choose to opt in this collection now (by choosing 'Y' at the below prompt), or at any time in the future by running the following command: gcloud config set disable_usage_reporting false Do you want to help improve the Google Cloud SDK (y/N)? n Your current Cloud SDK version is: 321.0.0 The latest available version is: 321.0.0 ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ │ Components │ ├───────────────┬──────────────────────────────────────────────────────┬──────────────────────────┬──────────┤ │ Status │ Name │ ID │ Size │ ├───────────────┼──────────────────────────────────────────────────────┼──────────────────────────┼──────────┤ │ Not Installed │ App Engine Go Extensions │ app-engine-go │ 4.8 MiB │ │ Not Installed │ Appctl │ appctl │ 18.5 MiB │ │ Not Installed │ Cloud Bigtable Command Line Tool │ cbt │ 7.6 MiB │ │ Not Installed │ Cloud Bigtable Emulator │ bigtable │ 6.6 MiB │ │ Not Installed │ Cloud Datalab Command Line Tool │ datalab │ < 1 MiB │ │ Not Installed │ Cloud Datastore Emulator │ cloud-datastore-emulator │ 18.4 MiB │ │ Not Installed │ Cloud Firestore Emulator │ cloud-firestore-emulator │ 41.5 MiB │ │ Not Installed │ Cloud Pub/Sub Emulator │ pubsub-emulator │ 56.4 MiB │ │ Not Installed │ Cloud SQL Proxy │ cloud_sql_proxy │ 7.4 MiB │ │ Not Installed │ Emulator Reverse Proxy │ emulator-reverse-proxy │ 14.5 MiB │ │ Not Installed │ Google Cloud Build Local Builder │ cloud-build-local │ 6.2 MiB │ │ Not Installed │ Google Container Registry's Docker credential helper │ docker-credential-gcr │ 1.8 MiB │ │ Not Installed │ Kind │ kind │ 4.4 MiB │ │ Not Installed │ Kustomize │ kustomize │ 22.8 MiB │ │ Not Installed │ Minikube │ minikube │ 22.8 MiB │ │ Not Installed │ Nomos CLI │ nomos │ 17.7 MiB │ │ Not Installed │ Skaffold │ skaffold │ 16.1 MiB │ │ Not Installed │ anthos-auth │ anthos-auth │ 16.4 MiB │ │ Not Installed │ config-connector │ config-connector │ 42.0 MiB │ │ Not Installed │ gcloud Alpha Commands │ alpha │ < 1 MiB │ │ Not Installed │ gcloud Beta Commands │ beta │ < 1 MiB │ │ Not Installed │ gcloud app Java Extensions │ app-engine-java │ 59.6 MiB │ │ Not Installed │ gcloud app PHP Extensions │ app-engine-php │ 21.9 MiB │ │ Not Installed │ gcloud app Python Extensions │ app-engine-python │ 6.1 MiB │ │ Not Installed │ gcloud app Python Extensions (Extra Libraries) │ app-engine-python-extras │ 27.1 MiB │ │ Not Installed │ kpt │ kpt │ 12.0 MiB │ │ Not Installed │ kubectl │ kubectl │ < 1 MiB │ │ Not Installed │ kubectl-oidc │ kubectl-oidc │ 16.4 MiB │ │ Not Installed │ pkg │ pkg │ │ │ Installed │ BigQuery Command Line Tool │ bq │ < 1 MiB │ │ Installed │ Cloud SDK Core Libraries │ core │ 15.9 MiB │ │ Installed │ Cloud Storage Command Line Tool │ gsutil │ 3.5 MiB │ └───────────────┴──────────────────────────────────────────────────────┴──────────────────────────┴──────────┘ To install or remove components at your current SDK version [321.0.0], run: $ gcloud components install COMPONENT_ID $ gcloud components remove COMPONENT_ID To update your SDK installation to the latest version [321.0.0], run: $ gcloud components update Modify profile to update your $PATH and enable shell command completion? Do you want to continue (Y/n)? y The Google Cloud SDK installer will now prompt you to update an rc file to bring the Google Cloud CLIs into your environment. Enter a path to an rc file to update, or leave blank to use [/Users/leodu/.bash_profile]: Backing up [/Users/leodu/.bash_profile] to [/Users/leodu/.bash_profile.backup]. [/Users/leodu/.bash_profile] has been updated. ==> Start a new shell for the changes to take effect. For more information on how to get started, please visit: https://cloud.google.com/sdk/docs/quickstarts
Start a new shell for the changes to take effect.
Initialize the SDK. Below command works both on MacOS and Linux.
$ ./google-cloud-sdk/bin/gcloud init
Welcome! This command will take you through the configuration of gcloud. Your current configuration has been set to: [default] You can skip diagnostics next time by using the following flag: gcloud init --skip-diagnostics Network diagnostic detects and fixes local network connection issues. Checking network connection...done. Reachability Check passed. Network diagnostic passed (1/1 checks passed). You must log in to continue. Would you like to log in (Y/n)? y Your browser has been opened to visit: https://accounts.google.com/o/oauth2/auth?### You are logged in as: [li###u@tianzhui.cloud]. Pick cloud project to use: [1] ### ... [12] Create a new project Please enter numeric choice or text value (must exactly match list item): 2 Your current project has been set to: [###]. Not setting default zone/region (this feature makes it easier to use [gcloud compute] by setting an appropriate default value for the --zone and --region flag). See https://cloud.google.com/compute/docs/gcloud-compute section on how to set default compute region and zone manually. If you would like [gcloud init] to be able to do this for you the next time you run it, make sure the Compute Engine API is enabled for your project on the https://console.developers.google.com/apis page. Created a default .boto configuration file at [/Users/leodu/.boto]. See this file and [https://cloud.google.com/storage/docs/gsutil/commands/config] for more information about configuring Google Cloud Storage. Your Google Cloud SDK is configured and ready to use! * Commands that require authentication will use liusongdu@tianzhui.cloud by default * Commands will reference project `###` by default Run `gcloud help config` to learn how to change individual settings This gcloud configuration is called [default]. You can create additional configurations if you work with multiple accounts and/or projects. Run `gcloud topic configurations` to learn more. Some things to try next: * Run `gcloud --help` to see the Cloud Platform services you can interact with. And run `gcloud help COMMAND` to get help on any gcloud command. * Run `gcloud topic --help` to learn about advanced features of the SDK like arg files and output formatting
When executing below docker build command, make sure it could communicate with gcloud API endpoints. Otherwise maybe see below error.
ERROR: gcloud crashed (TransportError): ('Connection aborted.', ConnectionResetError(54, 'Connection reset by peer')) If you would like to report this issue, please run the following command: gcloud feedback To check gcloud for common problems, please run the following command: gcloud info --run-diagnostics
Authentication methods
Configure Container Registry credentials for use with Docker directly in gcloud.
Use the gcloud tool to configure authentication. Log in to gcloud as the user that will run Docker commands. Configure authentication with user credentials
$ ./google-cloud-sdk/bin/gcloud auth login
Go to the following link in your browser: https://accounts.google.com/o/oauth2/auth?### Enter verification code: 4***8 You are now logged in as [l###u@tianzhui.cloud]. Your current project is [###]. You can change this setting by running: $ gcloud config set project PROJECT_ID
Configure Docker.
$ ./google-cloud-sdk/bin/gcloud auth configure-docker
WARNING: `docker-credential-gcloud` not in system PATH. gcloud's Docker credential helper can be configured but it will not work until this is corrected. Adding credentials for all GCR repositories. WARNING: A long list of credential helpers may cause delays running 'docker build'. We recommend passing the registry name to configure only the registry you are using. After update, the following will be written to your Docker config file located at [/root/.docker/config.json]: { "credHelpers": { "gcr.io": "gcloud", "us.gcr.io": "gcloud", "eu.gcr.io": "gcloud", "asia.gcr.io": "gcloud", "staging-k8s.gcr.io": "gcloud", "marketplace.gcr.io": "gcloud" } } Do you want to continue (Y/n)? y Docker configuration file updated.Docker is now configured to authenticate with Container Registry.
# export PATH=$PATH:~/google-cloud-sdk/bin
References
Installing Google Cloud SDK
Authentication methods
-