-
-
Notifications
You must be signed in to change notification settings - Fork 322
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add module for Fedora CoreOS on Google Cloud
* Add Typhoon Fedora CoreOS on Google Cloud as alpha * Add docs on uploading the Fedora CoreOS GCP gzipped tarball to Google Cloud storage to create a boot disk image
- Loading branch information
Showing
25 changed files
with
1,682 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,254 @@ | ||
# Google Cloud | ||
|
||
!!! danger | ||
Typhoon for Fedora CoreOS is an alpha. Please report Fedora CoreOS bugs to [Fedora](https://github.com/coreos/fedora-coreos-tracker/issues) and Typhoon issues to Typhoon. | ||
|
||
In this tutorial, we'll create a Kubernetes v1.17.2 cluster on Google Compute Engine with Fedora CoreOS. | ||
|
||
We'll declare a Kubernetes cluster using the Typhoon Terraform module. Then apply the changes to create a network, firewall rules, health checks, controller instances, worker managed instance group, load balancers, and TLS assets. | ||
|
||
Controller hosts are provisioned to run an `etcd-member` peer and a `kubelet` service. Worker hosts run a `kubelet` service. Controller nodes run `kube-apiserver`, `kube-scheduler`, `kube-controller-manager`, and `coredns`, while `kube-proxy` and `calico` (or `flannel`) run on every node. A generated `kubeconfig` provides `kubectl` access to the cluster. | ||
|
||
## Requirements | ||
|
||
* Google Cloud Account and Service Account | ||
* Google Cloud DNS Zone (registered Domain Name or delegated subdomain) | ||
* Terraform v0.12.6+ and [terraform-provider-ct](https://github.com/poseidon/terraform-provider-ct) installed locally | ||
|
||
## Terraform Setup | ||
|
||
Install [Terraform](https://www.terraform.io/downloads.html) v0.12.6+ on your system. | ||
|
||
```sh | ||
$ terraform version | ||
Terraform v0.12.16 | ||
``` | ||
|
||
Add the [terraform-provider-ct](https://github.com/poseidon/terraform-provider-ct) plugin binary for your system to `~/.terraform.d/plugins/`, noting the final name. | ||
|
||
```sh | ||
wget https://github.com/poseidon/terraform-provider-ct/releases/download/v0.4.0/terraform-provider-ct-v0.4.0-linux-amd64.tar.gz | ||
tar xzf terraform-provider-ct-v0.4.0-linux-amd64.tar.gz | ||
mv terraform-provider-ct-v0.4.0-linux-amd64/terraform-provider-ct ~/.terraform.d/plugins/terraform-provider-ct_v0.4.0 | ||
``` | ||
|
||
Read [concepts](/architecture/concepts/) to learn about Terraform, modules, and organizing resources. Change to your infrastructure repository (e.g. `infra`). | ||
|
||
``` | ||
cd infra/clusters | ||
``` | ||
|
||
## Provider | ||
|
||
Login to your Google Console [API Manager](https://console.cloud.google.com/apis/dashboard) and select a project, or [signup](https://cloud.google.com/free/) if you don't have an account. | ||
|
||
Select "Credentials" and create a service account key. Choose the "Compute Engine Admin" and "DNS Administrator" roles and save the JSON private key to a file that can be referenced in configs. | ||
|
||
```sh | ||
mv ~/Downloads/project-id-43048204.json ~/.config/google-cloud/terraform.json | ||
``` | ||
|
||
Configure the Google Cloud provider to use your service account key, project-id, and region in a `providers.tf` file. | ||
|
||
```tf | ||
provider "google" { | ||
version = "3.4.0" | ||
project = "project-id" | ||
region = "us-central1" | ||
credentials = file("~/.config/google-cloud/terraform.json") | ||
} | ||
provider "ct" { | ||
version = "0.4.0" | ||
} | ||
``` | ||
|
||
Additional configuration options are described in the `google` provider [docs](https://www.terraform.io/docs/providers/google/index.html). | ||
|
||
!!! tip | ||
Regions are listed in [docs](https://cloud.google.com/compute/docs/regions-zones/regions-zones) or with `gcloud compute regions list`. A project may contain multiple clusters across different regions. | ||
|
||
## Fedora CoreOS Images | ||
|
||
Fedora CoreOS publishes images for Google Cloud, but does not yet upload them. Google Cloud allows [custom boot images](https://cloud.google.com/compute/docs/images/import-existing-image) to be uploaded to a bucket and imported into your project. | ||
|
||
[Download](https://getfedora.org/coreos/download/) the Fedora CoreOS GCP gzipped tarball. Then upload the file to a GCS storage bucket. | ||
|
||
``` | ||
gsutil list | ||
gsutil cp fedora-coreos-31.20200113.3.1-gcp.x86_64.tar.gz gs://BUCKET_NAME | ||
``` | ||
|
||
Create a Google Compute Engine image from the bucket file. | ||
|
||
``` | ||
gcloud compute images create fedora-coreos-31-20200113-3-1 --source-uri gs://BUCKET/fedora-coreos-31.20200113.3.1-gcp.x86_64.tar.gz | ||
``` | ||
|
||
## Cluster | ||
|
||
Define a Kubernetes cluster using the module `google-cloud/fedora-coreos/kubernetes`. | ||
|
||
```tf | ||
module "yavin" { | ||
source = "git::https://github.com/poseidon/typhoon//google-cloud/fedora-coreos/kubernetes?ref=development-sha" | ||
# Google Cloud | ||
cluster_name = "yavin" | ||
region = "us-central1" | ||
dns_zone = "example.com" | ||
dns_zone_name = "example-zone" | ||
# temporary | ||
os_image = "fedora-coreos-31-20200113-3-1" | ||
# configuration | ||
ssh_authorized_key = "ssh-rsa AAAAB3Nz..." | ||
# optional | ||
worker_count = 2 | ||
} | ||
``` | ||
|
||
Reference the [variables docs](#variables) or the [variables.tf](https://github.com/poseidon/typhoon/blob/master/google-cloud/container-linux/kubernetes/variables.tf) source. | ||
|
||
## ssh-agent | ||
|
||
Initial bootstrapping requires `bootstrap.service` be started on one controller node. Terraform uses `ssh-agent` to automate this step. Add your SSH private key to `ssh-agent`. | ||
|
||
```sh | ||
ssh-add ~/.ssh/id_rsa | ||
ssh-add -L | ||
``` | ||
|
||
## Apply | ||
|
||
Initialize the config directory if this is the first use with Terraform. | ||
|
||
```sh | ||
terraform init | ||
``` | ||
|
||
Plan the resources to be created. | ||
|
||
```sh | ||
$ terraform plan | ||
Plan: 64 to add, 0 to change, 0 to destroy. | ||
``` | ||
|
||
Apply the changes to create the cluster. | ||
|
||
```sh | ||
$ terraform apply | ||
module.yavin.null_resource.bootstrap: Still creating... (10s elapsed) | ||
... | ||
module.yavin.null_resource.bootstrap: Still creating... (5m30s elapsed) | ||
module.yavin.null_resource.bootstrap: Still creating... (5m40s elapsed) | ||
module.yavin.null_resource.bootstrap: Creation complete (ID: 5768638456220583358) | ||
|
||
Apply complete! Resources: 62 added, 0 changed, 0 destroyed. | ||
``` | ||
|
||
In 4-8 minutes, the Kubernetes cluster will be ready. | ||
|
||
## Verify | ||
|
||
[Install kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/) on your system. Obtain the generated cluster `kubeconfig` from module outputs (e.g. write to a local file). | ||
|
||
``` | ||
resource "local_file" "kubeconfig-yavin" { | ||
content = module.yavin.kubeconfig-admin | ||
filename = "/home/user/.kube/configs/yavin-config" | ||
} | ||
``` | ||
|
||
List nodes in the cluster. | ||
|
||
``` | ||
$ export KUBECONFIG=/home/user/.kube/configs/yavin-config | ||
$ kubectl get nodes | ||
NAME ROLES STATUS AGE VERSION | ||
yavin-controller-0.c.example-com.internal <none> Ready 6m v1.17.2 | ||
yavin-worker-jrbf.c.example-com.internal <none> Ready 5m v1.17.2 | ||
yavin-worker-mzdm.c.example-com.internal <none> Ready 5m v1.17.2 | ||
``` | ||
|
||
List the pods. | ||
|
||
``` | ||
$ kubectl get pods --all-namespaces | ||
NAMESPACE NAME READY STATUS RESTARTS AGE | ||
kube-system calico-node-1cs8z 2/2 Running 0 6m | ||
kube-system calico-node-d1l5b 2/2 Running 0 6m | ||
kube-system calico-node-sp9ps 2/2 Running 0 6m | ||
kube-system coredns-1187388186-dkh3o 1/1 Running 0 6m | ||
kube-system coredns-1187388186-zj5dl 1/1 Running 0 6m | ||
kube-system kube-apiserver-controller-0 1/1 Running 0 6m | ||
kube-system kube-controller-manager-controller-0 1/1 Running 0 6m | ||
kube-system kube-proxy-117v6 1/1 Running 0 6m | ||
kube-system kube-proxy-9886n 1/1 Running 0 6m | ||
kube-system kube-proxy-njn47 1/1 Running 0 6m | ||
kube-system kube-scheduler-controller-0 1/1 Running 0 6m | ||
``` | ||
|
||
## Going Further | ||
|
||
Learn about [maintenance](/topics/maintenance/) and [addons](/addons/overview/). | ||
|
||
## Variables | ||
|
||
Check the [variables.tf](https://github.com/poseidon/typhoon/blob/master/google-cloud/container-linux/kubernetes/variables.tf) source. | ||
|
||
### Required | ||
|
||
| Name | Description | Example | | ||
|:-----|:------------|:--------| | ||
| cluster_name | Unique cluster name (prepended to dns_zone) | "yavin" | | ||
| region | Google Cloud region | "us-central1" | | ||
| dns_zone | Google Cloud DNS zone | "google-cloud.example.com" | | ||
| dns_zone_name | Google Cloud DNS zone name | "example-zone" | | ||
| ssh_authorized_key | SSH public key for user 'core' | "ssh-rsa AAAAB3NZ..." | | ||
|
||
Check the list of valid [regions](https://cloud.google.com/compute/docs/regions-zones/regions-zones) and list Fedora CoreOS [images](https://cloud.google.com/compute/docs/images) with `gcloud compute images list | grep fedora-coreos`. | ||
|
||
#### DNS Zone | ||
|
||
Clusters create a DNS A record `${cluster_name}.${dns_zone}` to resolve a TCP proxy load balancer backed by controller instances. This FQDN is used by workers and `kubectl` to access the apiserver(s). In this example, the cluster's apiserver would be accessible at `yavin.google-cloud.example.com`. | ||
|
||
You'll need a registered domain name or delegated subdomain on Google Cloud DNS. You can set this up once and create many clusters with unique names. | ||
|
||
```tf | ||
resource "google_dns_managed_zone" "zone-for-clusters" { | ||
dns_name = "google-cloud.example.com." | ||
name = "example-zone" | ||
description = "Production DNS zone" | ||
} | ||
``` | ||
|
||
!!! tip "" | ||
If you have an existing domain name with a zone file elsewhere, just delegate a subdomain that can be managed on Google Cloud (e.g. google-cloud.mydomain.com) and [update nameservers](https://cloud.google.com/dns/update-name-servers). | ||
|
||
### Optional | ||
|
||
| Name | Description | Default | Example | | ||
|:-----|:------------|:--------|:--------| | ||
| asset_dir | Absolute path to a directory where generated assets should be placed (contains secrets) | "" (disabled) | "/home/user/.secrets/clusters/yavin" | | ||
| controller_count | Number of controllers (i.e. masters) | 1 | 3 | | ||
| worker_count | Number of workers | 1 | 3 | | ||
| controller_type | Machine type for controllers | "n1-standard-1" | See below | | ||
| worker_type | Machine type for workers | "n1-standard-1" | See below | | ||
| os_image | Fedora CoreOS image for compute instances | "" | "fedora-coreos-31-20200113-3-1" | | ||
| disk_size | Size of the disk in GB | 40 | 100 | | ||
| worker_preemptible | If enabled, Compute Engine will terminate workers randomly within 24 hours | false | true | | ||
| controller_snippets | Controller Fedora CoreOS Config snippets | [] | UNSUPPORTED | | ||
| worker_snippets | Worker Fedora CoreOS Config snippets | [] | UNSUPPORTED | | ||
| networking | Choice of networking provider | "calico" | "calico" or "flannel" | | ||
| pod_cidr | CIDR IPv4 range to assign to Kubernetes pods | "10.2.0.0/16" | "10.22.0.0/16" | | ||
| service_cidr | CIDR IPv4 range to assign to Kubernetes services | "10.3.0.0/16" | "10.3.0.0/24" | | ||
| worker_node_labels | List of initial worker node labels | [] | ["worker-pool=default"] | | ||
|
||
Check the list of valid [machine types](https://cloud.google.com/compute/docs/machine-types). | ||
|
||
#### Preemption | ||
|
||
Add `worker_preemptible = "true"` to allow worker nodes to be [preempted](https://cloud.google.com/compute/docs/instances/preemptible) at random, but pay [significantly](https://cloud.google.com/compute/pricing) less. Clusters tolerate stopping instances fairly well (reschedules pods, but cannot drain) and preemption provides a nice reward for running fault-tolerant cluster systems.` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2020 Typhoon Authors | ||
Copyright (c) 2020 Dalton Hubble | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Typhoon <img align="right" src="https://storage.googleapis.com/poseidon/typhoon-logo.png"> | ||
|
||
Typhoon is a minimal and free Kubernetes distribution. | ||
|
||
* Minimal, stable base Kubernetes distribution | ||
* Declarative infrastructure and configuration | ||
* Free (freedom and cost) and privacy-respecting | ||
* Practical for labs, datacenters, and clouds | ||
|
||
Typhoon distributes upstream Kubernetes, architectural conventions, and cluster addons, much like a GNU/Linux distribution provides the Linux kernel and userspace components. | ||
|
||
## Features <a href="https://www.cncf.io/certification/software-conformance/"><img align="right" src="https://storage.googleapis.com/poseidon/certified-kubernetes.png"></a> | ||
|
||
* Kubernetes v1.17.2 (upstream) | ||
* Single or multi-master, [Calico](https://www.projectcalico.org/) or [flannel](https://github.com/coreos/flannel) networking | ||
* On-cluster etcd with TLS, [RBAC](https://kubernetes.io/docs/admin/authorization/rbac/)-enabled, [network policy](https://kubernetes.io/docs/concepts/services-networking/network-policies/) | ||
* Advanced features like [worker pools](https://typhoon.psdn.io/advanced/worker-pools/), [preemptible](https://typhoon.psdn.io/cl/google-cloud/#preemption) workers, and [snippets](https://typhoon.psdn.io/advanced/customization/#container-linux) customization | ||
* Ready for Ingress, Prometheus, Grafana, and other optional [addons](https://typhoon.psdn.io/addons/overview/) | ||
|
||
## Docs | ||
|
||
Please see the [official docs](https://typhoon.psdn.io) and the Google Cloud [tutorial](https://typhoon.psdn.io/cl/google-cloud/). | ||
|
Oops, something went wrong.