Book Image

Serverless Architectures with Kubernetes

By : Onur Yılmaz, Sathsara Sarathchandra
Book Image

Serverless Architectures with Kubernetes

By: Onur Yılmaz, Sathsara Sarathchandra

Overview of this book

Kubernetes has established itself as the standard platform for container management, orchestration, and deployment. By learning Kubernetes, you’ll be able to design your own serverless architecture by implementing the function-as-a-service (FaaS) model. After an accelerated, hands-on overview of the serverless architecture and various Kubernetes concepts, you’ll cover a wide range of real-world development challenges faced by real-world developers, and explore various techniques to overcome them. You’ll learn how to create production-ready Kubernetes clusters and run serverless applications on them. You'll see how Kubernetes platforms and serverless frameworks such as Kubeless, Apache OpenWhisk and OpenFaaS provide the tooling to help you develop serverless applications on Kubernetes. You'll also learn ways to select the appropriate framework for your upcoming project. By the end of this book, you’ll have the skills and confidence to design your own serverless applications using the power and flexibility of Kubernetes.
Table of Contents (11 chapters)
2
2. Introduction to Serverless in the Cloud

4. Kubernetes Deep Dive

Activity 4: Collect Gold Prices in a MySQL Database in Kubernetes

Solution:

Execute the following steps to complete this activity:

  1. Create an application to retrieve the gold price from CurrencyLayer and insert it into the MySQL database.

    It is possible to implement this function in Go with the following main.go file:

    ...
    func main() {
        db, err := sql.Open("mysql",  ...
        ...
        r, err := http.Get(fmt.Sprintf(„http://apilayer.net/api/...
       ...
        stmt, err := db.Prepare("INSERT INTO GoldPrices(price) VALUES(?)")
        ...
        _, err = stmt.Exec(target.Quotes.USDXAU)
        ...
        log.Printf("Successfully inserted the price: %v", target.Quotes.USDXAU)
        ...
    }

    The main function starts with database connection...