From 4554a216f1473b584742d1cb490d923592bd902a Mon Sep 17 00:00:00 2001 From: Andrea Luzzardi Date: Thu, 3 Jun 2021 20:34:18 -0700 Subject: [PATCH] docs: kubernetes: support kind/gke/eks Signed-off-by: Andrea Luzzardi --- .markdownlint.yaml | 3 + docs/tutorials/kubernetes.md | 219 ++++++++++++++++++++++++++++++++--- 2 files changed, 208 insertions(+), 14 deletions(-) diff --git a/.markdownlint.yaml b/.markdownlint.yaml index bedc3c97..5323121b 100644 --- a/.markdownlint.yaml +++ b/.markdownlint.yaml @@ -3,3 +3,6 @@ default: true # MD013/line-length - Line length MD013: false + +# MD033 - Inline HTML. Needed for tabs in docusaurus +MD033: false diff --git a/docs/tutorials/kubernetes.md b/docs/tutorials/kubernetes.md index e71c2238..2c0e83e6 100644 --- a/docs/tutorials/kubernetes.md +++ b/docs/tutorials/kubernetes.md @@ -1,15 +1,27 @@ # Kubernetes -This example illustrates how to use `dagger` to build, push and deploy Docker +This tutorial illustrates how to use `dagger` to build, push and deploy Docker images to Kubernetes. +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + ## Prerequisites -### Setup a local Kubernetes cluster +For this tutorial, you will need a Kubernetes cluster. -While dagger supports GKE and EKS, for the purpose of this example, we'll be -using [kind](https://kind.sigs.k8s.io/) to install a local Kubernetes cluster -in addition to a local container registry, no cloud account required. + + + + +[Kind](https://kind.sigs.k8s.io/docs/user/quick-start) is a tool for running local Kubernetes clusters using Docker. 1\. Install kind @@ -47,6 +59,23 @@ EOF docker network connect kind registry ``` + + + + +This tutorial can be run against a [GCP GKE](https://cloud.google.com/kubernetes-engine) cluster and [GCR](https://cloud.google.com/container-registry +) + + + + + +This tutorial can be run against a [AWS EKS](https://aws.amazon.com/eks/ +) cluster and [ECR](https://aws.amazon.com/ecr/) + + + + ## Initialize a Dagger Workspace and Environment ```shell @@ -57,13 +86,6 @@ dagger new default ## Create a basic plan - - Create a file named `.dagger/env/default/plan/manifest.cue` and add the following configuration to it. @@ -101,6 +123,17 @@ used to create a _nginx_ deployment. Next, create `.dagger/env/default/plan/main.cue`. + + + + ```cue title=".dagger/env/default/plan/main.cue" package main @@ -114,7 +147,7 @@ kubeconfig: string @dagger(input) // deploy uses the `dagger.io/kubernetes` package to apply a manifest to a // Kubernetes cluster. -deploy: kubernetes.#Apply & { +deploy: kubernetes.#Resources & { // reference the `kubeconfig` input above "kubeconfig": kubeconfig @@ -123,6 +156,65 @@ deploy: kubernetes.#Apply & { } ``` + + + + +```cue title=".dagger/env/default/plan/main.cue" +package main + +import ( + "dagger.io/kubernetes" + "dagger.io/gcp/gke" +) + +// gkeConfig used for deployment +gkeConfig: gke.#KubeConfig @dagger(input) + +kubeconfig: gkeConfig.kubeconfig + +// deploy uses the `dagger.io/kubernetes` package to apply a manifest to a +// Kubernetes cluster. +deploy: kubernetes.#Resources & { + // reference the `kubeconfig` input above + "kubeconfig": kubeconfig + + // reference to the manifest defined in `manifest.cue` + "manifest": manifest +} +``` + + + + + +```cue title=".dagger/env/default/plan/main.cue" +package main + +import ( + "dagger.io/kubernetes" + "dagger.io/aws/eks" +) + +// eksConfig used for deployment +eksConfig: eks.#KubeConfig @dagger(input) + +kubeconfig: eksConfig.kubeconfig + +// deploy uses the `dagger.io/kubernetes` package to apply a manifest to a +// Kubernetes cluster. +deploy: kubernetes.#Resources & { + // reference the `kubeconfig` input above + "kubeconfig": kubeconfig + + // reference to the manifest defined in `manifest.cue` + "manifest": manifest +} +``` + + + + This defines: - `kubeconfig` a _string_ **input**: kubernetes configuration (`~/.kube/config`) @@ -142,6 +234,38 @@ $ dagger up You can inspect the list of inputs (both required and optional) using `dagger input list`: + + + + + + ```shell $ dagger input list Input Type Description @@ -149,13 +273,80 @@ kubeconfig string ~/.kube/config file used for deployment deploy.namespace string Kubernetes Namespace to deploy to ``` -Let's provide the missing input: + + + + +```shell +$ dagger input list +Input Type Description +deploy.namespace string Kubernetes Namespace to deploy to +gkeConfig.config.region string GCP region +gkeConfig.config.project string GCP project +gkeConfig.config.serviceKey dagger.#Secret GCP service key +gkeConfig.clusterName string GKE cluster name +``` + + + + + +```shell +$ dagger input list +Input Type Description +deploy.namespace string Kubernetes Namespace to deploy to +eksConfig.config.region string AWS region +eksConfig.config.accessKey dagger.#Secret AWS access key +eksConfig.config.secretKey dagger.#Secret AWS secret key +eksConfig.clusterName string EKS cluster name +``` + + + + +Let's provide the missing inputs: + + + + ```shell # we'll use the ~/.kube/config created by `kind` dagger input text kubeconfig -f ~/.kube/config ``` + + + + +```shell +dagger input text gkeConfig.config.project +dagger input text gkeConfig.config.region +dagger input text gkeConfig.clusterName +dagger input secret gkeConfig.config.serviceKey -f +``` + + + + + +```shell +dagger input text eksConfig.config.region +dagger input text eksConfig.clusterName +dagger input secret eksConfig.config.accessKey +dagger input secret eksConfig.config.secretKey +``` + + + + ### Deploying Now is time to deploy to kubernetes.