Skip to content

Commit

Permalink
Utils
Browse files Browse the repository at this point in the history
  • Loading branch information
J0hn-B authored May 22, 2023
1 parent 4355dc0 commit e701d7c
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 71 deletions.
1 change: 1 addition & 0 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ tasks:
- terraform -chdir='{{fromSlash "kube/bootstrap"}}' init
status: # If terraform is initialized, skip the task
- terraform -chdir='{{fromSlash "kube/bootstrap"}}' state list

deploy:
desc: "Bootstrap cluster and deploy apps"
cmds:
Expand Down
60 changes: 60 additions & 0 deletions docs/release_v0.1.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#

This release focuses on Taskfile tasks and Go templating examples in tasks.

## Features and Tools

- `[Task](https://taskfile.dev/):` a cross-platform alternative to Make, supporting and showcasing `Go templates`.

- `Terraform:` bootstraps the cluster and applies the ArgoCD helm chart.

## Getting Started

> **In this example, a WSL distro using a kubeconfig file located in the Windows user's home directory**
1. Update the `KUBE` variable in [Taskfile.yml](../Taskfile.yaml) to match your path.

```yaml
env:
CLUSTER_NAME: kubepal
KUBE: export KUBECONFIG=/mnt/c/Users/{{.USER}}/.kube/config
```
2. Update the `kube/bootstrap/backend.tf` to match `the path of your local kubeconfig file`:

> Warning: Variables, locals, and functions may not be used here.

```hcl
terraform {
backend "kubernetes" {
secret_suffix = "state"
config_paths = [
"/mnt/c/Users/devops/.kube/config", # WSL path
"c:\\Users\\devops\\.kube\\config" # PowerShell path
]
}
}
```

3. Run `task --list` in WSL or PowerShell to see the available tasks and the updated kubeconfig path.

```shell
$ task
task: Available tasks for this project:
* create: Create and access a k3d cluster.
* delete: Delete cluster
* deploy: Bootstrap cluster and deploy apps
* tf_init: Initialize terraform
* run:connect: Get a shell to a running container
* run:pod: Create a temporary interactive pod, install some tools on it, and experiment
* run:start: Go template if statement
* run:test: Go template functions and examples using Powershell and Bash
```

4. The `task deploy` command will create the cluster, deploy ArgoCD, and deploy the apps.
5. The `task delete` command will delete the cluster.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions kube/bootstrap/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ resource "helm_release" "argocd" {

// read values from file
values = [
file("${path.module}/argocd_chart_values.yml")
file("${path.module}./base/argocd_chart_values.yml")
]
}

// Create an ArgoCd Ingress
resource "kubernetes_manifest" "argocd_ingress" {
manifest = yamldecode(
file("${path.module}/argocd_ingress.yml")
file("${path.module}./base/argocd_ingress.yml")
)
depends_on = [
helm_release.argocd
Expand Down
59 changes: 8 additions & 51 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,60 +1,17 @@
# Kubepal

A local [`k3d`](https://k3d.io) cluster setup, ready to deploy your apps, pre-packaged with a few useful tools.
Designed to be used with both, WSL and Powershell simultaneously.
`Kubepal` is a local k3d cluster setup designed for cluster configuration development and app deployment experimentation.

- [Task](https://taskfile.dev/) used as a `make` alternative, supports Go templates and is cross-platform.
Key features:

- Terraform used to deploy the ArgoCD helm chart after the cluster is up and running.
- ✅ Disposable and Quick-to-Use: Create and delete the cluster set up with a single command.

GitOps focused, will try to replicate an easy to use, temporary local cluster setup for development/testing purposes.
- ✅ GitOps Ready: Replicate GitOps practices in a local environment.

A tools and code snippets collection for future reference.
- ✅ Testing Ground for Tools: Explore and experiment with various tools and their configurations.

## Getting started
Releases:

- On [`Taskfile.yml`](./Taskfile.yaml), update the KUBE variable ( if necessary ) to match your WSL path to kubeconfig file on Windows host:
- Each release represents a snapshot of tools and their configurations as described in the release docs "Focus" section.

```yml
env:
CLUSTER_NAME: kubepal
KUBE: export KUBECONFIG=/mnt/c/Users/{{.USER}}/.kube/config # WSL path to kubeconfig file on Windows host
```
- Update the [`config_paths`](./kube/bootstrap/backend.tf) list to match your local `kubeconfig file` path:

```hcl
// Warning: Variables, locals and functions may not be used here.
config_paths = [
"/mnt/c/Users/devops/.kube/config",
"c:\\Users\\devops\\.kube\\config"
]
```

- Run `task --list` on WSL or Powershell to see the available tasks and the updated `kubeconfig` path.

```bash
task: Available tasks for this project:
* create: Create and access a k3d cluster.
If operating on WSL, the KUBECONFIG env var will point to the Windows host.
Kubeconfig path: /mnt/c/Users/devops/.kube/config
* delete: Delete cluster
* deploy: Bootstrap cluster and deploy apps
* tf_init: Initialize terraform
* run:clean: Clean up /.kube/config
* run:connect: Get a shell to a running container
* run:path: Convert a string from / path format to \
* run:start: Go template if statement
* run:temp_pod: Create a temporary interactive pod, install some tools on it, and experiment
* run:test: Go template functions and examples using Powershell and Bash
```

- `task deploy` will perform all steps to create the cluster, deploy ArgoCD and deploy the apps.

- `task delete` will delete the cluster.
- [x] [v0.1.0](/docs/release_v0.1.0.md)
30 changes: 12 additions & 18 deletions utils/helper_tasks.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,36 @@
version: "3"

tasks:
clean:
desc: "Clean up /.kube/config"
cmds:
- :> $KUBECONFIG
env:
POD_NAME: kubepal-tester

temp_pod:
tasks:
pod:
desc: "Create a temporary interactive pod, install some tools on it, and experiment "
cmds:
- kubectl run -i --tty tester --image debian
- kubectl run -i --tty {{.POD_NAME}} --image debian
status:
- kubectl get pods {{.POD_NAME}} # If pod exists, skip the task

connect:
desc: "Get a shell to a running container"
cmds:
- task: pod
- kubectl exec --stdin --tty {{.POD_NAME}} -- /bin/bash
vars:
POD_NAME:
sh: kubectl get po | grep $(yq '.metadata.name' text/deploy.yml) | awk '{print $1}'

test:
desc: "Go template functions and examples using Powershell and Bash"
desc: "Go template functions examples using Powershell and Bash"
cmds:
- '{{if eq OS "windows"}}powershell "Get-ComputerInfo | select WindowsProductName"{{else}}cat /etc/os-release{{end}}'

- '{{ if and (eq OS "windows") (eq (env "KUBECONFIG") "") }} echo "OS is windows and KUBECONFIG var is empty" {{end}}'
silent: true

start:
desc: "Go template if statement"
desc: "Start Docker Desktop on Windows"
cmds:
# Run a command if OS is windows
- '{{if eq OS "windows"}}powershell Start-Process "\"C:\ProgramData\Microsoft\Windows\Start Menu\Docker Desktop"\"{{end}}'
silent: true

path:
desc: "Convert a string from / path format to \\"
cmds:
# Run a command if OS is windows
- echo '{{fromSlash "kube/bootstrap/"}}'
# If OS is linux, echo a message
- '{{if eq OS "linux"}}echo "This is a Windows only command"{{end}}'
silent: true

0 comments on commit e701d7c

Please sign in to comment.