Merge pull request #924 from slumbering/kubernetes-docs

use a more generic command
This commit is contained in:
Sam Alba 2021-08-30 13:58:37 -07:00 committed by GitHub
commit 9e1f59ed69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -119,7 +119,7 @@ mkdir kube
Kubernetes objects are located inside the `k8s` folder: Kubernetes objects are located inside the `k8s` folder:
```shell ```shell
tree k8s ls -l k8s
# k8s # k8s
# ├── deployment.yaml # ├── deployment.yaml
# └── service.yaml # └── service.yaml
@ -144,13 +144,13 @@ kubectl get deployments
kubectl get service kubectl get service
# NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE # NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
# todoapp-service NodePort 10.96.225.114 <none> 80:32658/TCP 11m # todoapp-service NodePort 10.96.225.114 <none> 80:32658/TCP 11m
``` ```
The next step is to transpose it in Cue. Before continuing, clean everything: The next step is to transpose it in Cue. Before continuing, clean everything:
```shell ```shell
kubectl delete -f k8s/ kubectl delete -f k8s/
# deployment.apps "todoapp" deleted # deployment.apps "todoapp" deleted
# service "todoapp-service" deleted # service "todoapp-service" deleted
``` ```
@ -160,26 +160,26 @@ kubectl delete -f k8s/
Create a file named `todoapp.cue` and add the following configuration to it. Create a file named `todoapp.cue` and add the following configuration to it.
```cue title="todoapp/kube/todoapp.cue" ```cue title="todoapp/kube/todoapp.cue"
package main package main
import ( import (
"alpha.dagger.io/dagger" "alpha.dagger.io/dagger"
"alpha.dagger.io/kubernetes" "alpha.dagger.io/kubernetes"
) )
// input: kubernetes objects directory to deploy to // input: kubernetes objects directory to deploy to
// set with `dagger input dir manifest ./k8s -e kube` // set with `dagger input dir manifest ./k8s -e kube`
manifest: dagger.#Artifact & dagger.#Input manifest: dagger.#Artifact & dagger.#Input
// Deploy the manifest to a kubernetes cluster // Deploy the manifest to a kubernetes cluster
todoApp: kubernetes.#Resources & { todoApp: kubernetes.#Resources & {
"kubeconfig": kubeconfig "kubeconfig": kubeconfig
source: manifest source: manifest
} }
``` ```
This defines a `todoApp` variable containing the Kubernetes objects used to create a todoapp deployment. It also This defines a `todoApp` variable containing the Kubernetes objects used to create a todoapp deployment. It also
references a `kubeconfig` value defined above: references a `kubeconfig` value defined below:
<Tabs defaultValue="kind" <Tabs defaultValue="kind"
groupId="provider" groupId="provider"
@ -189,16 +189,16 @@ values={[
<TabItem value="kind"> <TabItem value="kind">
The above `config.cue` defines: The following `config.cue` defines:
- `kubeconfig` a generic value created to embed this string `kubeconfig` value - `kubeconfig` a generic value created to embed this string `kubeconfig` value
```cue title="todoapp/kube/config.cue" ```cue title="todoapp/kube/config.cue"
package main package main
import ( import (
"alpha.dagger.io/dagger" "alpha.dagger.io/dagger"
) )
// set with `dagger input text kubeconfig -f "$HOME"/.kube/config -e kube` // set with `dagger input text kubeconfig -f "$HOME"/.kube/config -e kube`
kubeconfig: string & dagger.#Input kubeconfig: string & dagger.#Input
@ -217,22 +217,22 @@ The below `config.cue` defines:
```cue title="todoapp/kube/config.cue" ```cue title="todoapp/kube/config.cue"
package main package main
import ( import (
"alpha.dagger.io/gcp" "alpha.dagger.io/gcp"
"alpha.dagger.io/gcp/gke" "alpha.dagger.io/gcp/gke"
) )
// Value created for generic reference of `kubeconfig` in `todoapp.cue` // Value created for generic reference of `kubeconfig` in `todoapp.cue`
kubeconfig: gkeConfig.kubeconfig kubeconfig: gkeConfig.kubeconfig
// gcpConfig used for Google connection // gcpConfig used for Google connection
gcpConfig: gcp.#Config gcpConfig: gcp.#Config
// gkeConfig used for deployment // gkeConfig used for deployment
gkeConfig: gke.#KubeConfig & { gkeConfig: gke.#KubeConfig & {
// config field references `gkeConfig` value to set in once // config field references `gkeConfig` value to set in once
config: gcpConfig config: gcpConfig
} }
``` ```
@ -249,22 +249,22 @@ The below `config.cue` defines:
```cue title="todoapp/kube/config.cue" ```cue title="todoapp/kube/config.cue"
package main package main
import ( import (
"alpha.dagger.io/aws" "alpha.dagger.io/aws"
"alpha.dagger.io/aws/eks" "alpha.dagger.io/aws/eks"
) )
// Value created for generic reference of `kubeconfig` in `todoapp.cue` // Value created for generic reference of `kubeconfig` in `todoapp.cue`
kubeconfig: eksConfig.kubeconfig kubeconfig: eksConfig.kubeconfig
// awsConfig for Amazon connection
awsConfig: aws.#Config
// eksConfig used for deployment // awsConfig for Amazon connection
eksConfig: eks.#KubeConfig & { awsConfig: aws.#Config
// eksConfig used for deployment
eksConfig: eks.#KubeConfig & {
// config field references `gkeConfig` value to set in once // config field references `gkeConfig` value to set in once
config: awsConfig config: awsConfig
} }
``` ```
@ -428,7 +428,7 @@ kubectl get deployments
Before continuing, cleanup deployment: Before continuing, cleanup deployment:
```shell ```shell
kubectl delete -f k8s/ kubectl delete -f k8s/
# deployment.apps "todoapp" deleted # deployment.apps "todoapp" deleted
# service "todoapp-service" deleted # service "todoapp-service" deleted
``` ```
@ -498,7 +498,7 @@ todoApp: {
// Update the image from manifest to use the deployed one // Update the image from manifest to use the deployed one
kustomization: kustomize.#Kustomize & { kustomization: kustomize.#Kustomize & {
source: manifest source: manifest
// Convert CUE to YAML. // Convert CUE to YAML.
kustomization: yaml.Marshal({ kustomization: yaml.Marshal({
resources: ["deployment.yaml", "service.yaml"] resources: ["deployment.yaml", "service.yaml"]
@ -510,7 +510,7 @@ todoApp: {
}) })
} }
// Deploy the customized manifest to a kubernetes cluster // Deploy the customized manifest to a kubernetes cluster
kubeSrc: kubernetes.#Resources & { kubeSrc: kubernetes.#Resources & {
"kubeconfig": kubeconfig "kubeconfig": kubeconfig
source: kustomization source: kustomization
@ -533,10 +533,10 @@ The two files have to be edited to do so.
```cue title="todoapp/kube/config.cue" ```cue title="todoapp/kube/config.cue"
package main package main
import ( import (
"alpha.dagger.io/gcp" "alpha.dagger.io/gcp"
"alpha.dagger.io/gcp/gcr" "alpha.dagger.io/gcp/gcr"
"alpha.dagger.io/gcp/gke" "alpha.dagger.io/gcp/gke"
) )
@ -544,12 +544,12 @@ import (
kubeconfig: gkeConfig.kubeconfig kubeconfig: gkeConfig.kubeconfig
// gcpConfig used for Google connection // gcpConfig used for Google connection
gcpConfig: gcp.#Config gcpConfig: gcp.#Config
// gkeConfig used for deployment // gkeConfig used for deployment
gkeConfig: gke.#KubeConfig & { gkeConfig: gke.#KubeConfig & {
// config field references `gkeConfig` value to set in once // config field references `gkeConfig` value to set in once
config: gcpConfig config: gcpConfig
} }
// gcrCreds used for remote image push // gcrCreds used for remote image push
@ -587,7 +587,7 @@ repository: dagger.#Artifact & dagger.#Input
registry: string & dagger.#Input registry: string & dagger.#Input
tag: "test-gcr" tag: "test-gcr"
// source of Kube config file. // source of Kube config file.
// set with `dagger input dir manifest ./k8s -e kube` // set with `dagger input dir manifest ./k8s -e kube`
manifest: dagger.#Artifact & dagger.#Input manifest: dagger.#Artifact & dagger.#Input
@ -611,7 +611,7 @@ todoApp: {
// Update the image of the deployment to the deployed image // Update the image of the deployment to the deployed image
kustomization: kustomize.#Kustomize & { kustomization: kustomize.#Kustomize & {
source: manifest source: manifest
// Convert CUE to YAML. // Convert CUE to YAML.
kustomization: yaml.Marshal({ kustomization: yaml.Marshal({
resources: ["deployment.yaml", "service.yaml"] resources: ["deployment.yaml", "service.yaml"]
@ -699,7 +699,7 @@ repository: dagger.#Artifact & dagger.#Input
registry: string & dagger.#Input registry: string & dagger.#Input
tag: "test-ecr" tag: "test-ecr"
// source of Kube config file. // source of Kube config file.
// set with `dagger input dir manifest ./k8s -e kube` // set with `dagger input dir manifest ./k8s -e kube`
manifest: dagger.#Artifact & dagger.#Input manifest: dagger.#Artifact & dagger.#Input
@ -722,7 +722,7 @@ todoApp: {
// Update the image of the deployment to the deployed image // Update the image of the deployment to the deployed image
kustomization: kustomize.#Kustomize & { kustomization: kustomize.#Kustomize & {
source: manifest source: manifest
// Convert CUE to YAML. // Convert CUE to YAML.
kustomization: yaml.Marshal({ kustomization: yaml.Marshal({
resources: ["deployment.yaml", "service.yaml"] resources: ["deployment.yaml", "service.yaml"]
@ -819,7 +819,7 @@ kubectl get deployments
Before continuing, cleanup deployment: Before continuing, cleanup deployment:
```shell ```shell
kubectl delete -f k8s/ kubectl delete -f k8s/
# deployment.apps "todoapp" deleted # deployment.apps "todoapp" deleted
# service "todoapp-service" deleted # service "todoapp-service" deleted
``` ```
@ -958,7 +958,7 @@ import (
"name": name "name": name
ports: "http": deployment.port ports: "http": deployment.port
} }
// Merge definitions and convert them back from CUE to YAML // Merge definitions and convert them back from CUE to YAML
manifest: yaml.MarshalStream([deployment.manifest, service.manifest]) manifest: yaml.MarshalStream([deployment.manifest, service.manifest])
} }
@ -1019,7 +1019,7 @@ todoApp: {
image: remoteImage.ref image: remoteImage.ref
} }
// Deploy the customized manifest to a kubernetes cluster // Deploy the customized manifest to a kubernetes cluster
kubeSrc: kubernetes.#Resources & { kubeSrc: kubernetes.#Resources & {
"kubeconfig": kubeconfig "kubeconfig": kubeconfig
manifest: deployment.manifest manifest: deployment.manifest
@ -1070,7 +1070,7 @@ todoApp: {
image: remoteImage.ref image: remoteImage.ref
} }
// Deploy the customized manifest to a kubernetes cluster // Deploy the customized manifest to a kubernetes cluster
kubeSrc: kubernetes.#Resources & { kubeSrc: kubernetes.#Resources & {
"kubeconfig": kubeconfig "kubeconfig": kubeconfig
manifest: deployment.manifest manifest: deployment.manifest
@ -1121,7 +1121,7 @@ todoApp: {
image: remoteImage.ref image: remoteImage.ref
} }
// Deploy the customized manifest to a kubernetes cluster // Deploy the customized manifest to a kubernetes cluster
kubeSrc: kubernetes.#Resources & { kubeSrc: kubernetes.#Resources & {
"kubeconfig": kubeconfig "kubeconfig": kubeconfig
manifest: deployment.manifest manifest: deployment.manifest