From 321d52bd0180d21235df33612b3be700015ae7c7 Mon Sep 17 00:00:00 2001 From: Crossplane Date: Tue, 17 Sep 2019 20:41:31 +0000 Subject: [PATCH] docs snapshot for crossplane version `master` --- .../cloud-providers/gcp/gcp-provider.md | 8 + docs/master/stacks-guide-gcp.md | 450 ++++++++++++++++++ docs/master/stacks-guide.md | 331 +++++++++++++ 3 files changed, 789 insertions(+) create mode 100644 docs/master/stacks-guide-gcp.md create mode 100644 docs/master/stacks-guide.md diff --git a/docs/master/cloud-providers/gcp/gcp-provider.md b/docs/master/cloud-providers/gcp/gcp-provider.md index 2cf45204..67b92560 100644 --- a/docs/master/cloud-providers/gcp/gcp-provider.md +++ b/docs/master/cloud-providers/gcp/gcp-provider.md @@ -62,6 +62,9 @@ gcloud --project $EXAMPLE_PROJECT_ID services enable sqladmin.googleapis.com # enable Redis API gcloud --project $EXAMPLE_PROJECT_ID services enable redis.googleapis.com +# enable Compute API +gcloud --project $EXAMPLE_PROJECT_ID services enable compute.googleapis.com + # enable Additional APIs needed for the example or project # See `gcloud services list` for a complete list @@ -79,6 +82,7 @@ gcloud projects add-iam-policy-binding $EXAMPLE_PROJECT_ID --member "serviceAcco gcloud projects add-iam-policy-binding $EXAMPLE_PROJECT_ID --member "serviceAccount:$EXAMPLE_SA" --role="roles/cloudsql.admin" gcloud projects add-iam-policy-binding $EXAMPLE_PROJECT_ID --member "serviceAccount:$EXAMPLE_SA" --role="roles/container.admin" gcloud projects add-iam-policy-binding $EXAMPLE_PROJECT_ID --member "serviceAccount:$EXAMPLE_SA" --role="roles/redis.admin" +gcloud projects add-iam-policy-binding $EXAMPLE_PROJECT_ID --member "serviceAccount:$EXAMPLE_SA" --role="roles/compute.networkAdmin" ``` ## Option 2: GCP Console in a Web Browser @@ -100,6 +104,7 @@ Create a GCP example project which we will use to host our example GKE cluster, - `Service Account User` - `Cloud SQL Admin` - `Kubernetes Engine Admin` + - `Compute Network Admin` - Click `Create` button - This should advance to the next section `3 Grant users access to this service account (optional)` - We don't need to assign any user or admin roles to this account for the example purposes, so you can leave following two fields blank: @@ -122,6 +127,9 @@ Create a GCP example project which we will use to host our example GKE cluster, - Enable `Cloud Memorystore for Redis` - Navigate to [Cloud Memorystore for Redis](https://console.developers.google.com/apis/api/redis.googleapis.com/overview) - Click `Enable` +- Enable `Compute Engine API` + - Navigate to [Compute Engine API](https://console.developers.google.com/apis/api/compute.googleapis.com/overview) + - Click `Enable` ### Enable Billing diff --git a/docs/master/stacks-guide-gcp.md b/docs/master/stacks-guide-gcp.md new file mode 100644 index 00000000..7feb2702 --- /dev/null +++ b/docs/master/stacks-guide-gcp.md @@ -0,0 +1,450 @@ +--- +title: "Crossplane Stacks Guide: GCP Setup" +toc: false +weight: 421 +indent: true +--- + +# Crossplane Stacks Guide: GCP Setup + +## Table of Contents + +1. [Introduction](#introduction) +2. [Install the GCP Stack](#install-the-gcp-stack) +3. [Configure GCP Account](#configure-gcp-account) +4. [Configure Crossplane GCP Provider](#configure-crossplane-gcp-provider) +5. [Set Up Network Resources](#set-up-network-resources) +6. [Configure Provider Resources](#configure-provider-resources) +7. [Recap](#recap) +8. [Next Steps](#next-steps) + +## Introduction + +In this guide, we will set up a GCP provider in Crossplane so that we +can install and use the [WordPress sample +stack][sample-wordpress-stack], which depends on MySQL and Kubernetes! + +Before we begin, you will need: + +* Everything from the [Crossplane Stacks Guide][stacks-guide] before the + cloud provider setup + - A `kubectl` pointing to a Crossplane control cluster + - The [Crossplane CLI][crossplane-cli] installed +* An account on [Google Cloud Platform][gcp] + +At the end, we will have: + +* A Crossplane control cluster configured to use GCP +* The boilerplate of a GCP-based project spun up +* Support in the control cluster for managing MySQL and Kubernetes + cluster dependencies +* A slightly better understanding of: + - The way cloud providers are configured in Crossplane + - The way dependencies for cloud-portable workloads are configured in + Crossplane + +We will **not** be teaching first principles in depth. Check out the +[Crossplane concepts document][crossplane-concepts] for that. + +## Install the GCP Stack + +After Crossplane has been installed, it can be extended with more +functionality by installing a [Crossplane Stack][stack-docs]! Let's +install the [stack for Google Cloud Platform][stack-gcp] (GCP) to add +support for that cloud provider. We can use the [Crossplane +CLI][crossplane-cli] for this operation. Since this is an infrastructure +stack, we need to specify that it's cluster-scoped by passing the +`--cluster` flag. + + +To install to a specific namespace, we can use the `generate-install` +command and pipe it to `kubectl apply` instead, which gives us more +control over how the stack's installation is handled. Everything is +a Kubernetes object! + +``` +kubectl create namespace gcp +kubectl crossplane stack generate-install --cluster 'crossplane/stack-gcp:master' stack-gcp | kubectl apply --namespace gcp -f - +``` + +If we wanted to use whatever the current namespace is, we could have +used `kubectl crossplane stack install` instead of using +`generate-install`. + +The namespace that we install the stack to is where the stack will +create the resources it manages. When a developer requests a resource by +creating a [resource claim][resource-claims-docs] in a namespace `mynamespace`, the +managed cloud provider resource and any secrets will be created in the +stack's namespace. Secrets will be copied over to `mynamespace`, and the +claim will be bound to the original resource claim. For more details +about resource claims and how they work, see the [documentation on +resource claims][resource-claims-docs]. + +For convenience, the next steps assume that you installed GCP stack into +the `gcp` namespace. + +## Configure GCP Account + +We will make use of the following services on GCP: + +* GKE +* CloudSQL Instance +* Network +* Subnetwork +* GlobalAddress +* Private Service Connection + +For all these to work, you need to [enable the following +APIs][gcp-enable-apis] in your GCP project: + +* Compute Engine API +* Service Networking API +* Kubernetes Engine API + +We will also need to tell Crossplane how to use the credentials for the +GCP account. For this exercise, the GCP account that we will tell +Crossplane about should have the following [roles +assigned][gcp-assign-roles]: + +* Cloud SQL Admin +* Compute Network Admin +* Kubernetes Engine Admin +* Service Account User + +You need to get JSON file of the service account you’ll use. In the next +sections, this file will be referred to as +`crossplane-gcp-provider-key.json` + +You can create the JSON file by using the [gcloud +command][gcp-create-keys] and specifying a file name of +`crossplane-gcp-provider-key.json`. If you use Crossplane's [GCP +credentials script][gcp-credentials], this is taken care of for you. + +## Configure Crossplane GCP Provider + +Before creating any resources, we need to create and configure a cloud +provider in Crossplane. This helps Crossplane know how to connect to the cloud +provider. All the requests from Crossplane to GCP will use the +credentials attached to the provider object. The following command +assumes that you have a `crossplane-gcp-provider-key.json` file that +belongs to the account you’d like Crossplane to use. Run the command +after changing `[your-demo-project-id]` to your actual GCP project id. +You should be able to get the project id from the JSON credentials file +or from the GCP Console. + +``` +export PROJECT_ID=[your-demo-project-id] +export BASE64ENCODED_GCP_PROVIDER_CREDS=$(base64 crossplane-gcp-provider-key.json | tr -d "\n") +``` + +The environment variable `PROJECT_ID` is going to be used in multiple +YAML files in the next steps, while `BASE64ENCODED_GCP_PROVIDER_CREDS` +is only needed for this step. + +Now we’ll create our `Secret` that contains the credential and +`Provider` resource that refers to that secret: + +``` +cat > provider.yaml < network.yaml < environment.yaml < namespace.yaml < +[crossplane-cli]: https://github.com/crossplaneio/crossplane-cli +[crossplane-gcp-networking-docs]: https://github.com/crossplaneio/crossplane/blob/master/design/one-pager-resource-connectivity-mvp.md#google-cloud-platform +[stacks-guide]: stacks-guide.md + +[crossplane-concepts]: concepts.md + +[gcp-credentials]: https://github.com/crossplaneio/crossplane/blob/master/cluster/examples/gcp-credentials.sh +[gcp-enable-apis]: https://cloud.google.com/endpoints/docs/openapi/enable-api +[gcp-assign-roles]: https://cloud.google.com/iam/docs/granting-roles-to-service-accounts +[gcp-create-keys]: https://cloud.google.com/sdk/gcloud/reference/iam/service-accounts/keys/create + +[gcp]: https://cloud.google.com/ + +[stacks-guide-continue]: stacks-guide.html#install-support-for-our-application-into-crossplane +[sample-wordpress-stack]: https://github.com/crossplaneio/sample-stack-wordpress +[stack-docs]: https://github.com/crossplaneio/crossplane/blob/master/design/design-doc-stacks.md#crossplane-stacks + +[stack-gcp]: https://github.com/crossplaneio/stack-gcp + +[resource-claims-docs]: concepts.md#resource-claims-and-resource-classes +[resource-classes-docs]: concepts.md#resource-claims-and-resource-classes +[portable-classes-docs]: https://github.com/crossplaneio/crossplane/blob/master/design/one-pager-default-resource-class.md + +[crossplane-sample-gcp-provider]: https://github.com/crossplaneio/crossplane/blob/master/cluster/examples/workloads/kubernetes/wordpress/gcp/provider.yaml +[crossplane-sample-gcp-network]: https://github.com/crossplaneio/crossplane/blob/master/cluster/examples/workloads/kubernetes/wordpress/gcp/network.yaml +[crossplane-sample-gcp-environment]: https://github.com/crossplaneio/crossplane/blob/master/cluster/examples/workloads/kubernetes/wordpress/gcp/environment.yaml +[crossplane-sample-gcp-namespace]: https://github.com/crossplaneio/crossplane/blob/master/cluster/examples/workloads/kubernetes/wordpress/gcp/namespace.yaml diff --git a/docs/master/stacks-guide.md b/docs/master/stacks-guide.md new file mode 100644 index 00000000..386d8800 --- /dev/null +++ b/docs/master/stacks-guide.md @@ -0,0 +1,331 @@ +--- +title: "Crossplane Stacks Guide" +toc: true +weight: 401 +indent: false +--- + +# Crossplane Stacks Guide + + +## Table of Contents + +1. [Introduction](#introduction) +2. [Concepts](#concepts) +3. [Before you get started](#before-you-get-started) +4. [Install the Crossplane CLI](#install-the-crossplane-cli) +5. [Install and configure Crossplane](#install-and-configure-crossplane) +6. [Install support for our application into + Crossplane](#install-support-for-our-application-into-crossplane) +7. [Create a Wordpress](#create-a-wordpress) +8. [Clean up](#clean-up) +9. [Conclusion](#conclusion) +10. [Next steps](#next-steps) +11. [References](#references) + +## Introduction + +Welcome to the Crossplane Stack guide! In this document, we will: + +* Learn how to install an existing stack +* Interact with a stack to see how to use it +* Glimpse what is possible with a stack +* Touch a little bit on how stacks work + +We will **not**: + +* Learn first principles (see the [concepts + document][crossplane-concepts] for that level of detail) +* Develop our own stack from scratch (go to [this development + guide][stack-developer-guide] to learn how to do that) + +Let's go! + +## Concepts + +There are a bunch of things you might want to know to fully understand what's happening in this document. This guide won't cover them, but there are other ones that do. Here are some links! + +* [Crossplane concepts][crossplane-concepts] +* [Kubernetes concepts][kubernetes-concepts] + +## Before you get started + +This guide assumes you are using a *nix-like environment. It also assumes you have a basic working familiarity with the following: + +* The terminal environment +* Setting up cloud provider accounts for the cloud provider you want to + use +* [Kubernetes][kubernetes-docs] and [kubectl][kubectl-docs] + +You will need: + +* A *nix-like environment +* A cloud provider account, for the cloud provider of your choice (out + of the supported providers) +* A locally-configured kubectl which points to a configured Kubernetes + cluster. We will put Crossplane in this cluster, and we'll refer to it + as the control cluster. + +## Install the Crossplane CLI + +To interact with stacks, we're going to use the [Crossplane +CLI][crossplane-cli], because it's more convenient. To install it, we +can use the one-line curl bash: + +``` +RELEASE=0.0.1 +curl -sL https://raw.githubusercontent.com/crossplaneio/crossplane-cli/"${RELEASE}"/bootstrap.sh | bash +``` + +To use the latest release, you can use `master` as the `RELEASE` instead +of using a specific version. + +## Install and configure Crossplane + +To use Crossplane, we'll need to install and configure it. In this case, +we want to use Crossplane with a cloud provider, so we'll need to +configure the provider. + +### Install Crossplane + +The recommended way of installing Crossplane is by using +[helm][helm-install]. We can grab the most stable version currently +available by using: + +``` +helm repo add crossplane-alpha https://charts.crossplane.io/alpha +helm install --name crossplane --namespace crossplane-system crossplane-alpha/crossplane +``` + +For more options for installing, including how to install a more +bleeding-edge version, or how to uninstall, see the [full install +documentation][crossplane-install-docs]. + +### Create the application namespace + +[Kubernetes namespaces][kubernetes-namespace-docs] are used to isolate +resources in the same cluster, and we'll use them in our Crossplane +control cluster too. Let's create a namespace for our application's +resources. We'll call it `app-project1-dev` for the purposes of this +guide, but any name can be used. + +``` +kubectl create namespace app-project1-dev +``` + +The reason we need to create the namespace before we configure the cloud +provider is because we will be setting up some cloud provider +configuration in that namespace. The configuration will help our +application not care about which specific provider it uses. For more +details on how this works, see the Crossplane documentation on [portable +classes][portable-classes-docs]. + +### Configure support for your cloud provider + +Next we'll set up support for our cloud provider of choice! See the +provider-specific guides: + +* [AWS][aws-setup] +* [GCP][gcp-setup] +* [Azure][azure-setup] + +Then come back here! Don't worry; we'll still be here when you're ready. + +Don't see your favorite cloud provider? [Help us add +support][provider-stack-developer-guide] for it! + +## Install support for our application into Crossplane + +Now that we've got Crossplane set up and configured to use a cloud +provider, we're ready to add support for creating WordPresses! We'll do +this using a Crossplane Stack. For more information about stacks, see +the [full Stack documentation][stack-docs]. + +We can use the [Crossplane CLI][crossplane-cli] to install our stack which adds support for +Wordpress. Let's install it into a namespace for our project, which +we'll call `app-project1-dev` for the purposes of this guide. To install +to the current namespace, `install` can be used, but since we want to +install to a specific namespace, we will use `generate-install`: + +``` +kubectl crossplane stack generate-install 'crossplane/sample-stack-wordpress:latest' 'sample-stack-wordpress' | kubectl apply --namespace app-project1-dev -f - +``` + +Using the `generate-install` command and piping the output to `kubectl +apply` instead of using the `install` command gives us more control over +how the stack's installation is handled. Everything is a Kubernetes +object! + +This pulls the stack package from a registry to install it into +Crossplane. For more details about how to use the CLI, see the +[documentation for the CLI][crossplane-cli-docs]. For more details about how stacks work behind +the scenes, see the documentation about the [stack +manager][stack-manager-docs] and the [stack +format][stack-format-docs]. + +## Create a Wordpress + +Now that Crossplane supports Wordpress creation, we can ask Crossplane +to spin up a Wordpress for us. We can do this by creating a Kubernetes +resource that our Wordpress stack will recognize: + +``` +cat > my-wordpress.yaml < +[crossplane-cli]: https://github.com/crossplaneio/crossplane-cli +[crossplane-cli-docs]: https://github.com/crossplaneio/crossplane-cli/blob/master/README.md +[crossplane-concepts]: concepts.md +[crossplane-install-docs]: install-crossplane.md + +[kubernetesapplicationresource-docs]: TODO +[claims-docs]: concepts.md#resource-claims-and-resource-classes +[resource-classes-docs]: concepts.md#resource-claims-and-resource-classes +[portable-classes-docs]: https://github.com/crossplaneio/crossplane/blob/master/design/one-pager-default-resource-class.md +[workloads-docs]: concepts.md#resources-and-workloads + +[kubernetes-concepts]: https://kubernetes.io/docs/concepts/ +[kubernetes-docs]: https://kubernetes.io/docs/home/ +[kubernetes-namespaces-docs]: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/ +[kubectl-docs]: https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands + +[helm-install]: https://github.com/helm/helm#install + +[aws-docs]: https://docs.aws.amazon.com/ +[gcp-docs]: https://cloud.google.com/docs/ +[azure-docs]: https://docs.microsoft.com/azure/ + +[aws-setup]: TODO +[gcp-setup]: stacks-guide-gcp.md +[azure-setup]: TODO + +[stack-docs]: https://github.com/crossplaneio/crossplane/blob/master/design/design-doc-stacks.md#crossplane-stacks +[stack-quick-start]: https://github.com/crossplaneio/crossplane-cli#quick-start-stacks +[stack-concepts]: https://github.com/crossplaneio/crossplane/blob/master/design/design-doc-stacks.md#crossplane-stacks +[stack-manager-docs]: https://github.com/crossplaneio/crossplane/blob/master/design/design-doc-stacks.md#installation-flow +[stack-format-docs]: https://github.com/crossplaneio/crossplane/blob/master/design/design-doc-stacks.md#stack-package-format +[stack-registry]: TODO +[stack-developer-guide]: TODO +[provider-stack-developer-guide]: TODO