my external IP is: 52.24.188.63 (source: jsonip.com)
% +``` + +Our application is up and running and we can connect to it! + +## Cleaning up + +To cleanup the resources we created, we need to go into each project directory and run the command + +```bash +$ pulumi destroy --yes && pulumi stack rm +``` + +Once the resources have been deleted, then we can follow the interactive prompt to delete the stack. + +## Wrapping Up + +In this post, we have discussed how we would break our infrastructure into logically grouped projects and how we share +information between these projects. You can find a runable version of this infrastructure in our +[examples](https://github.com/pulumi/examples/tree/master/aws-stackreference-architecture) repository. + +This demonstrates the suggested way of architecting Pulumi applications both for operability and collaboration. + +You can try this code today get started with Pulumi today at [https://www.pulumi.com](/) and +following the [Getting Started](/docs/get-started/aws/) for managing AWS resources with Pulumi. diff --git a/docs/blog/architecture-as-code-intro/architecture.png b/docs/blog/architecture-as-code-intro/architecture.png new file mode 100644 index 0000000..4b86f9c Binary files /dev/null and b/docs/blog/architecture-as-code-intro/architecture.png differ diff --git a/docs/blog/architecture-as-code-intro/index.md b/docs/blog/architecture-as-code-intro/index.md new file mode 100644 index 0000000..20a536b --- /dev/null +++ b/docs/blog/architecture-as-code-intro/index.md @@ -0,0 +1,302 @@ +--- +title: "Architecture as Code" +description: " An overview of infrastructure architecture and implementations with Pulumi." +date: 2020-03-20 +authors: ["sophia-parafina"] +tags: ["Kubernetes","serverless","architecture-as-code"] +--- +# Architecture as Code + + + +Abstraction is key to building resilient systems because it encapsulates behavior and decouples code, letting each component perform its function independently. The same principles apply to infrastructure, where we want to declare behavior or state and not implementation details. As an industry, we've moved away from monolithic applications to distributed systems such as serverless, microservices, Kubernetes, and virtual machine deployments. In this article, we'll take a closer look at the characteristics of these architectures and how Pulumi can abstract the components that comprise these systems. + +## Virtual Machines + +Virtual machines arose from the need to use expensive hardware more efficiently. VMs are more efficient because they share the host server, decreasing the number of physical servers needed to run applications. A group of hosts can also be aggregated so that it behaves as a single virtual host with large memory and processing capabilities. Virtual machines can emulate other environments that have specific hardware requirements or capabilities that the host machine does not have, thus reducing the need for specific hardware or operating systems. Virtualization provides the host machine isolation from the guest virtual machines by limiting access to the host machine through an abstraction layer. Finally, virtualization has the added advantage of providing a fine degree of control over resources available to the virtual machine. + +If virtual machines are part of your infrastructure, Pulumi lets you create virtual machines programmatically across cloud service providers. The JavaScript example below illustrates how to deploy a virtual machine on Google Cloud Platform. The script spins up a Debian based instance and creates a network with an open port 22 to let you configure and manage the machine as needed. + +```js +const gcp = require("@pulumi/gcp"); +const fs = require("fs"); + +// Create a network +const network = new gcp.compute.Network("network"); +const computeFirewall = new gcp.compute.Firewall("firewall", { + network: network.id, + allows: [{ + protocol: "tcp", + ports: [ "22", "80" ], + }], +}); + +// Read the configuration script +const startupScript = fs.readFileSync("config.sh", "utf-8") + +// Create a Virtual Machine Instance. +const computeInstance = new gcp.compute.Instance("instance", { + machineType: "f1-micro", + zone: "us-central1-a", + metadataStartupScript: startupScript, + bootDisk: { initializeParams: { image: "debian-cloud/debian-9" } }, + networkInterfaces: [{ + network: network.id, + // accessConfigs must include a single empty config to request an ephemeral IP. + accessConfigs: [{}], + }], +}); + +// Export the name and IP address of the Instance. +exports.instanceName = computeInstance.name; +exports.instanceIP = computeInstance.networkInterfaces.apply(ni => ni[0].accessConfigs[0].natIp); +``` + +This is the configuration script, `config.sh`, referenced in the code: + +```bash +#!/bin/bash +echo "Hello, World!" > index.html +nohup python -m SimpleHTTPServer 80 & +``` + +When the virtual machine is created, it reads the configuration file that creates a webserver. This a basic example, but it shows how to configure virtual machines programmatically, which is useful for scaling horizontally. + +## Serverless + +Serverless is a computing architecture characterized by server-side logic running in stateless containers that are invoked by events. They are typically ephemeral (often are available for only one call), and managed by third-party cloud providers. Serverless is also called Functions as a Service, or FaaS, and well-known implementations include AWS Lambda and Fargate, Azure Functions, and Google Cloud Run and Cloud Functions. + +A significant benefit of serverless is that it's a polyglot platform that allows developers to choose languages optimized for a task. For example, scripting languages like JavaScript or Python may be more responsive than a language such as Java. Serverless functions can support both synchronous and asynchronous calls. There are use cases that require an immediate response such as processing a video stream and instances where returning the result immediately is not critical as in an ETL batch job. + +A key part of serverless architecture is an API Gateway that provides logical routes for mapping standard HTTP operations such as GET, PUT, POST, and DELETE to functions. The gateway makes development easier since these are standard and well-known interfaces. In addition to an API Gateway, the serverless platform should provide REST endpoints that allow you to manage the deploy with a CLI, portal, or an automation script. Finally, serverless architecture is extensible and supports integration with event sources and resources from the cloud provider through webhooks and other mechanisms. + +The following example illustrates how to deploy two functions using TypeScript, one written in Python and the other written in Go. You can find the [full example](https://github.com/pulumi/examples/tree/master/gcp-ts-serverless-raw) in the Pulumi GitHub repository. + +```ts +import * as gcp from "@pulumi/gcp"; +import { asset } from "@pulumi/pulumi"; + +const bucket = new gcp.storage.Bucket("bucket"); + +// Google Cloud Function in Python + +const bucketObjectPython = new gcp.storage.BucketObject("python-zip", { + bucket: bucket.name, + source: new asset.AssetArchive({ + ".": new asset.FileArchive("./pythonfunc"), + }), +}); + +const functionPython = new gcp.cloudfunctions.Function("python-func", { + sourceArchiveBucket: bucket.name, + runtime: "python37", + sourceArchiveObject: bucketObjectPython.name, + entryPoint: "handler", + triggerHttp: true, + availableMemoryMb: 128, +}); + +export const pythonEndpoint = functionPython.httpsTriggerUrl; + +// Google Cloud Function in Go + +const bucketObjectGo = new gcp.storage.BucketObject("go-zip", { + bucket: bucket.name, + source: new asset.AssetArchive({ + ".": new asset.FileArchive("./gofunc"), + }), +}); + +const functionGo = new gcp.cloudfunctions.Function("go-func", { + sourceArchiveBucket: bucket.name, + runtime: "go111", + sourceArchiveObject: bucketObjectGo.name, + entryPoint: "Handler", + triggerHttp: true, + availableMemoryMb: 128, +}); + +export const goEndpoint = functionGo.httpsTriggerUrl; +``` + +## Kubernetes + +Kubernetes is a container orchestration system for deploying, scaling, and managing your application. Applications use multiple containers that contain code and dependencies needed for the code to execute. Kubernetes runs on a cluster of nodes and containers are deployed in pods. Kubernetes manages the pods by replacing containers that fail and removing containers that don't respond. It can also scale the number of containers as needed and load balance the network traffic. These are some of the features that Kubernetes provides: + +- Load balancing and traffic distribution across the cluster +- Service discovery +- Create and manage containers +- Remove failed containers and reassign their resources to a new container +- Mount storage systems such as local storage and storage on public cloud providers +- Automated deployments based on different deploy methods such as canary or blue/green deployments +- Automated rollbacks to last known good state +- Secrets management + +The following example is based on the [Kubernetes Guestbook](https://kubernetes.io/docs/tutorials/stateless-application/guestbook/) example. The difference between this implementation and the original application is that instead of using YAML to declare the infrastructure, it uses a component written in TypeScript to create the service deployment which is implemented as `k8sjs`. + +```ts +import * as k8s from "@pulumi/kubernetes"; +import * as k8stypes from "@pulumi/kubernetes/types/input"; +import * as pulumi from "@pulumi/pulumi"; + +/** + * ServiceDeployment is an example abstraction that uses a class to fold together the common pattern of a + * Kubernetes Deployment and its associated Service object. + */ +export class ServiceDeployment extends pulumi.ComponentResource { + public readonly deployment: k8s.apps.v1.Deployment; + public readonly service: k8s.core.v1.Service; + public readonly ipAddress?: pulumi.Output




+
+
+
+ Future of Cloud Engineering: Architectures and Platforms
+
+
+ Future of Cloud Engineering: Architectures and Platforms
+
+
+
+ Future of Cloud Engineering: Culture, Process, ToolsHello, world!
+Made with �� with Pulumi
+ + + """ + + # Write our index.html into the site bucket + s3.BucketObject("index", + bucket=site_bucket.id, # reference to the s3.Bucket object + content=index_content, + key="index.html", # set the key of the object + content_type="text/html; charset=utf-8") # set the MIME type of the file + + # Set the access policy for the bucket so all objects are readable + s3.BucketPolicy("bucket-policy", bucket=site_bucket.id, policy={ + "Version": "2012-10-17", + "Statement": { + "Effect": "Allow", + "Principal": "*", + "Action": ["s3:GetObject"], + # Policy refers to bucket explicitly + "Resource": [pulumi.Output.concat("arn:aws:s3:::", site_bucket.id, "/*")] + }, + }) + + # Export the website URL + pulumi.export("website_url", site_bucket.website_endpoint) +``` + +We can write additional functions to [deploy and destroy](https://nbviewer.jupyter.org/github/pulumi/automation-api-examples/blob/main/python/pulumi_via_jupyter/automation_api.ipynb#Automating-your-deployment) the S3 static website. We deploy the stack by calling the `deploy_project` function and pass it the `s3_static_site` function, the Pulumi AWS plugin, and the AWS region. + +```python +s3_site = deploy_project("my_first_project", + s3_static_site, + plugins=[("aws", "v3.23.0")], + config={"aws:region": auto.ConfigValue(value="us-west-2")}) +``` + +You can view the resources that the function created in two ways. The standard method is to open the AWS console to see your resources. + + + +You can also view them with the [Pulumi console](https://app.pulumi.com) as a resource graph. + + + +The Pulumi console also displays updates to the static site and the changes made. + + + +Now that the static site has been deployed, we want to get the site URL. The `s3_static_site` function exports the website url. Pulumi returns the s3_site as an object with [outputs](/docs/intro/concepts/inputs-outputs/) that we use to retrieve the URL. There are several ways to check if the site is working, but a simple way is to open the URL in a web browser. + +```python +import webbrowser + +outputs = s3_site.outputs() + +webbrowser.open(url) +``` + + + +## Data Science Your Way + +In this simple example, we demonstrated how to create a static website from an S3 bucket, write content into the bucket, and set the access policy as a Python function. We called the function, which created a stack for the website. The stack is returned as a Python object with the site URL as an output. You can manage the site and view updates using the Pulumi console. + +Because it's code, you can create a separate module containing all the functions to create your infrastructure, import it into your notebooks, and reuse it. Pulumi lets you perform analysis and build models within a familiar environment while reducing the burden of managing infrastructure. You can find the complete example on [GitHub](https://github.com/pulumi/automation-api-examples/tree/main/python/pulumi_via_jupyter) including a Jupyter notebook for [database migration](https://github.com/pulumi/automation-api-examples/blob/main/python/pulumi_via_jupyter/database_migration.ipynb). + +Be sure to watch our video that explains the code in greater detail. + + diff --git a/docs/blog/data-science-in-the-cloud/pulumi_resource_graph.png b/docs/blog/data-science-in-the-cloud/pulumi_resource_graph.png new file mode 100644 index 0000000..23a3500 Binary files /dev/null and b/docs/blog/data-science-in-the-cloud/pulumi_resource_graph.png differ diff --git a/docs/blog/data-science-in-the-cloud/pulumi_updates.png b/docs/blog/data-science-in-the-cloud/pulumi_updates.png new file mode 100644 index 0000000..0ec8bab Binary files /dev/null and b/docs/blog/data-science-in-the-cloud/pulumi_updates.png differ diff --git a/docs/blog/data-science-on-demand-spinning-up-a-wallaroo-cluster-is-easy-with-pulumi/index.md b/docs/blog/data-science-on-demand-spinning-up-a-wallaroo-cluster-is-easy-with-pulumi/index.md new file mode 100644 index 0000000..f0cca7a --- /dev/null +++ b/docs/blog/data-science-on-demand-spinning-up-a-wallaroo-cluster-is-easy-with-pulumi/index.md @@ -0,0 +1,363 @@ +--- +title: "Data science on demand: spinning up a Wallaroo cluster" +description: "Find out how Wallaroo powered their cluster provisioning with Pulumi, for data science on demand." +date: 2018-11-02 +authors: ["marc-holmes","simon-zelazny"] +tags: ["guest-post"] +--- +# Data science on demand: spinning up a Wallaroo cluster is easy with Pulumi + + + +*This guest post is from Simon Zelazny of +[Wallaroo Labs](https://www.wallaroo.ai/). +Find out how Wallaroo powered their cluster provisioning with Pulumi, +for data science on demand.* + +Last month, we took a +[long-running pandas classifier](https://github.com/WallarooLabs/wallaroo_blog_examples/tree/master/provisioned-classifier/classifier) +and made it run faster by leveraging Wallaroo's parallelization +capabilities. This time around, we'd like to kick it up a notch and see +if we can keep scaling out to meet higher demand. We'd also like to be +as economical as possible: provision infrastructure as needed and +de-provision it when we're done processing. + +If you don't feel like reading the post linked above, here's a short +summary of the situation: there's a batch job that you're running every +hour, on the hour. This job receives a CSV file and classifies each row +of the file, using a Pandas-based algorithm. The run-time of the job is +starting to near the one-hour mark, and there's concern that the +pipeline will break down once the input data grows past a particular +point. + +In the blog post, we show how to split up the input data into smaller +dataframes, and distribute them among workers in an ad-hoc Wallaroo +cluster, running on one physical machine. Parallelizing the work in this +manner buys us a lot of time, and the batch job can continue processing +increasing amounts of data. + +Sure, we can handle a million rows in reasonable time, but what if the +data set grows by orders of magnitude? By running our classifier on a +local Wallaroo cluster, we were able to cut the processing time of a +million rows to ~16 minutes, thus fitting within our allotted time slot +of one hour. But if the input data is, say, 10x more, we're going to +have a hard time processing it all locally. + +Let's see how we can keep up with the data growth by launching a +cloud-based Wallaroo cluster on-demand, running the job, collecting the +data, and shutting down the cluster, all in a fully automated fashion. + +## Tools of the trade + +Wallaroo's big idea is that your application doesn't have to know +whether it's running on one process, several local processes, or a +distributed system comprising many physical machines. In this sense, +there's no extra work involved in 'migrating' our classifier application +from the previous blog post. + +We will need some tools to help us set up and manage our cluster in the +cloud. Wallaroo can work with a lot of different tools. Our friends at +Pulumi provide an excellent tool that removes the +headaches involved in provisioning infrastructure. We'll use Pulumi to +define, set up, and finally tear down our processing cluster in this +example. + +We'll also need [Ansible](https://www.ansible.com/) to start, stop, and +inspect the state of our cluster, and, last but not least, we'll need +an [AWS](https://aws.amazon.com/) account where our machines will live. + +Let's jump into it! + +## A sample run + +First of all, if you'd like to follow along (and spend some money +provisioning EC2 servers), please +[download and set up Pulumi](/docs/get-started/install/). + +Next, [clone the wallaroo blog examples repo](https://github.com/WallarooLabs/wallaroo_blog_examples) and +navigate to `provisioned-classifier`. If you followed along with the +previous Pandas blog post, you'll find our old application nested away +here, under`classifier`. What's more interesting are the two new +directories: `pulumi` and `ansible`. + +Without delving into details, let's see how to run our application on a +freshly-provisioned cluster in the EC2 cloud: + +```bash +make up run-cluster get-results down INPUT_LINES=1000000 CLUSTER_SIZE=3 +``` + + + +Let's break that down and see what's really going on here. + +1. `make up CLUSTER_SIZE=3` configures the cluster to consist of 3 +machines, and delegates to `pulumi up` the actual business of spinning +up the infrastructure. Our physical cluster will contain 3 nodes for +processing, and one extra metrics_host node for hosting our [Metrics +UI](https://docs.wallaroolabs.com/book/metrics/metrics-ui.html), and +collecting results. + +2. Once provisioning is complete, the next make +task: `run-cluster INPUT_LINES=1000000` uses our Ansible playbooks to +upload application code from `classifier/*` to all 3 machines +provisioned above, and then start up a Wallaroo cluster with 7 worker +processes per machine. + +3. Next, Ansible starts sending 1 million lines of our +[synthetic CSV data](https://github.com/WallarooLabs/wallaroo_blog_examples/blob/master/provisioned-classifier/bin/send.py), +and waits for 1 million lines to arrive at the `data_receiver` process. +When those lines arrive, they are compressed, and the cluster is shut +down. + +4. `make get-results` pulls the compressed result file +to `output/results.tgz`, + +5. And finally, `make down` destroys the cloud infrastructure that was +used to power our computation. + +## The Pulumi cluster definition + +Let's take a look at how our infrastructure is defined. This is the core +of the +[definition](https://github.com/WallarooLabs/wallaroo_blog_examples/blob/master/provisioned-classifier/pulumi/index.js): + +```javascript + function instance(name) { + return new aws.ec2.Instance( + name, + {associatePublicIpAddress: true, + instanceType: instanceType, + securityGroups: [secGrp.name], + ami: ami, + tags: {"Name": name}, + keyName: keyPair.keyName}) + } + + let metrics_host = instance("classifier-metrics_host"); + let initializer = instance("classifier-initializer"); + let workers = []; + for(var i=0; i