Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c8586d1ef4 | ||
|
|
316cba1cb8 | ||
|
|
13dba62b8d | ||
|
|
c2ff169c08 | ||
|
|
57a1dbfc6d | ||
|
|
efb39d6fc6 | ||
|
|
b784234430 | ||
|
|
aebad92426 | ||
|
|
8e67cfd5c9 | ||
|
|
10cc6d7e08 | ||
|
|
83c236c829 | ||
|
|
b6ab37691f | ||
|
|
c85af78025 | ||
|
|
2c2fc6dd97 | ||
|
|
3620b76139 |
@@ -45,8 +45,10 @@ var bootstrapCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
bootstrapVersion string
|
bootstrapVersion string
|
||||||
bootstrapComponents []string
|
bootstrapComponents []string
|
||||||
|
bootstrapRegistry string
|
||||||
|
bootstrapImagePullSecret string
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -61,7 +63,10 @@ func init() {
|
|||||||
"toolkit version")
|
"toolkit version")
|
||||||
bootstrapCmd.PersistentFlags().StringSliceVar(&bootstrapComponents, "components", defaultComponents,
|
bootstrapCmd.PersistentFlags().StringSliceVar(&bootstrapComponents, "components", defaultComponents,
|
||||||
"list of components, accepts comma-separated values")
|
"list of components, accepts comma-separated values")
|
||||||
|
bootstrapCmd.PersistentFlags().StringVar(&bootstrapRegistry, "registry", "docker.io/fluxcd",
|
||||||
|
"container registry where the toolkit images are published")
|
||||||
|
bootstrapCmd.PersistentFlags().StringVar(&bootstrapImagePullSecret, "image-pull-secret", "",
|
||||||
|
"Kubernetes secret name used for pulling the toolkit images from a private registry")
|
||||||
rootCmd.AddCommand(bootstrapCmd)
|
rootCmd.AddCommand(bootstrapCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,7 +78,7 @@ func generateInstallManifests(targetPath, namespace, tmpDir string) (string, err
|
|||||||
return "", fmt.Errorf("generating manifests failed: %w", err)
|
return "", fmt.Errorf("generating manifests failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := genInstallManifests(bootstrapVersion, namespace, bootstrapComponents, tkDir); err != nil {
|
if err := genInstallManifests(bootstrapVersion, namespace, bootstrapComponents, bootstrapRegistry, bootstrapImagePullSecret, tkDir); err != nil {
|
||||||
return "", fmt.Errorf("generating manifests failed: %w", err)
|
return "", fmt.Errorf("generating manifests failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,11 +54,13 @@ If a previous version is installed, then an in-place upgrade will be performed.`
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
installExport bool
|
installExport bool
|
||||||
installDryRun bool
|
installDryRun bool
|
||||||
installManifestsPath string
|
installManifestsPath string
|
||||||
installVersion string
|
installVersion string
|
||||||
installComponents []string
|
installComponents []string
|
||||||
|
installRegistry string
|
||||||
|
installImagePullSecret string
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -70,8 +72,12 @@ func init() {
|
|||||||
"toolkit version")
|
"toolkit version")
|
||||||
installCmd.Flags().StringSliceVar(&installComponents, "components", defaultComponents,
|
installCmd.Flags().StringSliceVar(&installComponents, "components", defaultComponents,
|
||||||
"list of components, accepts comma-separated values")
|
"list of components, accepts comma-separated values")
|
||||||
installCmd.Flags().StringVarP(&installManifestsPath, "manifests", "", "",
|
installCmd.Flags().StringVar(&installManifestsPath, "manifests", "",
|
||||||
"path to the manifest directory, dev only")
|
"path to the manifest directory, dev only")
|
||||||
|
installCmd.Flags().StringVar(&installRegistry, "registry", "docker.io/fluxcd",
|
||||||
|
"container registry where the toolkit images are published")
|
||||||
|
installCmd.Flags().StringVar(&installImagePullSecret, "image-pull-secret", "",
|
||||||
|
"Kubernetes secret name used for pulling the toolkit images from a private registry")
|
||||||
rootCmd.AddCommand(installCmd)
|
rootCmd.AddCommand(installCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +103,7 @@ func installCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
logger.Generatef("generating manifests")
|
logger.Generatef("generating manifests")
|
||||||
}
|
}
|
||||||
if kustomizePath == "" {
|
if kustomizePath == "" {
|
||||||
err = genInstallManifests(installVersion, namespace, installComponents, tmpDir)
|
err = genInstallManifests(installVersion, namespace, installComponents, installRegistry, installImagePullSecret, tmpDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("install failed: %w", err)
|
return fmt.Errorf("install failed: %w", err)
|
||||||
}
|
}
|
||||||
@@ -118,6 +124,7 @@ func installCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
} else if installExport {
|
} else if installExport {
|
||||||
fmt.Println("---")
|
fmt.Println("---")
|
||||||
fmt.Println("# GitOps Toolkit revision", installVersion, time.Now().Format(time.RFC3339))
|
fmt.Println("# GitOps Toolkit revision", installVersion, time.Now().Format(time.RFC3339))
|
||||||
|
fmt.Println("# Components:", strings.Join(installComponents, ","))
|
||||||
fmt.Print(yaml)
|
fmt.Print(yaml)
|
||||||
fmt.Println("---")
|
fmt.Println("---")
|
||||||
return nil
|
return nil
|
||||||
@@ -183,12 +190,15 @@ fieldSpecs:
|
|||||||
`
|
`
|
||||||
|
|
||||||
var kustomizationTmpl = `---
|
var kustomizationTmpl = `---
|
||||||
{{- $version := .Version }}
|
{{- $eventsAddr := .EventsAddr }}
|
||||||
|
{{- $registry := .Registry }}
|
||||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
kind: Kustomization
|
kind: Kustomization
|
||||||
namespace: {{.Namespace}}
|
namespace: {{.Namespace}}
|
||||||
|
|
||||||
transformers:
|
transformers:
|
||||||
- labels.yaml
|
- labels.yaml
|
||||||
|
|
||||||
resources:
|
resources:
|
||||||
- namespace.yaml
|
- namespace.yaml
|
||||||
- policies.yaml
|
- policies.yaml
|
||||||
@@ -196,6 +206,34 @@ resources:
|
|||||||
{{- range .Components }}
|
{{- range .Components }}
|
||||||
- {{.}}.yaml
|
- {{.}}.yaml
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|
||||||
|
patches:
|
||||||
|
- path: node-selector.yaml
|
||||||
|
target:
|
||||||
|
kind: Deployment
|
||||||
|
|
||||||
|
patchesJson6902:
|
||||||
|
{{- range $i, $component := .Components }}
|
||||||
|
{{- if ne $component "notification-controller" }}
|
||||||
|
- target:
|
||||||
|
group: apps
|
||||||
|
version: v1
|
||||||
|
kind: Deployment
|
||||||
|
name: {{$component}}
|
||||||
|
patch: |-
|
||||||
|
- op: replace
|
||||||
|
path: /spec/template/spec/containers/0/args/0
|
||||||
|
value: --events-addr={{$eventsAddr}}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
|
||||||
|
{{- if $registry }}
|
||||||
|
images:
|
||||||
|
{{- range $i, $component := .Components }}
|
||||||
|
- name: fluxcd/{{$component}}
|
||||||
|
newName: {{$registry}}/{{$component}}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
`
|
`
|
||||||
|
|
||||||
var kustomizationRolesTmpl = `---
|
var kustomizationRolesTmpl = `---
|
||||||
@@ -206,6 +244,23 @@ resources:
|
|||||||
nameSuffix: -{{.Namespace}}
|
nameSuffix: -{{.Namespace}}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
var nodeSelectorTmpl = `---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: all
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
nodeSelector:
|
||||||
|
kubernetes.io/arch: amd64
|
||||||
|
kubernetes.io/os: linux
|
||||||
|
{{- if .ImagePullSecret }}
|
||||||
|
imagePullSecrets:
|
||||||
|
- name: {{.ImagePullSecret}}
|
||||||
|
{{- end }}
|
||||||
|
`
|
||||||
|
|
||||||
func downloadManifests(version string, tmpDir string) error {
|
func downloadManifests(version string, tmpDir string) error {
|
||||||
ghURL := "https://github.com/fluxcd/toolkit/releases/latest/download/manifests.tar.gz"
|
ghURL := "https://github.com/fluxcd/toolkit/releases/latest/download/manifests.tar.gz"
|
||||||
if strings.HasPrefix(version, "v") {
|
if strings.HasPrefix(version, "v") {
|
||||||
@@ -240,15 +295,26 @@ func downloadManifests(version string, tmpDir string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func genInstallManifests(version string, namespace string, components []string, tmpDir string) error {
|
func genInstallManifests(version string, namespace string, components []string, registry, imagePullSecret, tmpDir string) error {
|
||||||
|
eventsAddr := ""
|
||||||
|
if utils.containsItemString(components, defaultNotification) {
|
||||||
|
eventsAddr = fmt.Sprintf("http://%s/", defaultNotification)
|
||||||
|
}
|
||||||
|
|
||||||
model := struct {
|
model := struct {
|
||||||
Version string
|
Version string
|
||||||
Namespace string
|
Namespace string
|
||||||
Components []string
|
Components []string
|
||||||
|
EventsAddr string
|
||||||
|
Registry string
|
||||||
|
ImagePullSecret string
|
||||||
}{
|
}{
|
||||||
Version: version,
|
Version: version,
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
Components: components,
|
Components: components,
|
||||||
|
EventsAddr: eventsAddr,
|
||||||
|
Registry: registry,
|
||||||
|
ImagePullSecret: imagePullSecret,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := downloadManifests(version, tmpDir); err != nil {
|
if err := downloadManifests(version, tmpDir); err != nil {
|
||||||
@@ -263,6 +329,10 @@ func genInstallManifests(version string, namespace string, components []string,
|
|||||||
return fmt.Errorf("generate labels failed: %w", err)
|
return fmt.Errorf("generate labels failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := utils.execTemplate(model, nodeSelectorTmpl, path.Join(tmpDir, "node-selector.yaml")); err != nil {
|
||||||
|
return fmt.Errorf("generate node selector failed: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
if err := utils.execTemplate(model, kustomizationTmpl, path.Join(tmpDir, "kustomization.yaml")); err != nil {
|
if err := utils.execTemplate(model, kustomizationTmpl, path.Join(tmpDir, "kustomization.yaml")); err != nil {
|
||||||
return fmt.Errorf("generate kustomization failed: %w", err)
|
return fmt.Errorf("generate kustomization failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,9 +104,10 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
defaultComponents = []string{"source-controller", "kustomize-controller", "helm-controller", "notification-controller"}
|
defaultComponents = []string{"source-controller", "kustomize-controller", "helm-controller", "notification-controller"}
|
||||||
defaultVersion = "latest"
|
defaultVersion = "latest"
|
||||||
defaultNamespace = "gitops-system"
|
defaultNamespace = "gitops-system"
|
||||||
|
defaultNotification = "notification-controller"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|||||||
@@ -19,10 +19,12 @@ package main
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/manifoldco/promptui"
|
"github.com/manifoldco/promptui"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1alpha1"
|
||||||
|
sourcev1 "github.com/fluxcd/source-controller/api/v1alpha1"
|
||||||
)
|
)
|
||||||
|
|
||||||
var uninstallCmd = &cobra.Command{
|
var uninstallCmd = &cobra.Command{
|
||||||
@@ -33,24 +35,24 @@ var uninstallCmd = &cobra.Command{
|
|||||||
tk uninstall --dry-run --namespace=gitops-system
|
tk uninstall --dry-run --namespace=gitops-system
|
||||||
|
|
||||||
# Uninstall all components and delete custom resource definitions
|
# Uninstall all components and delete custom resource definitions
|
||||||
tk uninstall --crds --namespace=gitops-system
|
tk uninstall --resources --crds --namespace=gitops-system
|
||||||
`,
|
`,
|
||||||
RunE: uninstallCmdRun,
|
RunE: uninstallCmdRun,
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
uninstallCRDs bool
|
uninstallCRDs bool
|
||||||
uninstallKustomizations bool
|
uninstallResources bool
|
||||||
uninstallDryRun bool
|
uninstallDryRun bool
|
||||||
uninstallSilent bool
|
uninstallSilent bool
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
uninstallCmd.Flags().BoolVarP(&uninstallKustomizations, "kustomizations", "", false,
|
uninstallCmd.Flags().BoolVar(&uninstallResources, "resources", false,
|
||||||
"removes all Kustomizations previously installed")
|
"removes custom resources such as Kustomizations, GitRepositories and HelmRepositories")
|
||||||
uninstallCmd.Flags().BoolVarP(&uninstallCRDs, "crds", "", false,
|
uninstallCmd.Flags().BoolVar(&uninstallCRDs, "crds", false,
|
||||||
"removes all CRDs previously installed")
|
"removes all CRDs previously installed")
|
||||||
uninstallCmd.Flags().BoolVarP(&uninstallDryRun, "dry-run", "", false,
|
uninstallCmd.Flags().BoolVar(&uninstallDryRun, "dry-run", false,
|
||||||
"only print the object that would be deleted")
|
"only print the object that would be deleted")
|
||||||
uninstallCmd.Flags().BoolVarP(&uninstallSilent, "silent", "s", false,
|
uninstallCmd.Flags().BoolVarP(&uninstallSilent, "silent", "s", false,
|
||||||
"delete components without asking for confirmation")
|
"delete components without asking for confirmation")
|
||||||
@@ -75,18 +77,19 @@ func uninstallCmdRun(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if uninstallKustomizations {
|
if uninstallResources {
|
||||||
logger.Actionf("uninstalling kustomizations")
|
logger.Actionf("uninstalling custom resources")
|
||||||
command := fmt.Sprintf("kubectl -n %s delete kustomizations --all --timeout=%s %s",
|
for _, kind := range []string{
|
||||||
namespace, timeout.String(), dryRun)
|
kustomizev1.KustomizationKind,
|
||||||
if _, err := utils.execCommand(ctx, ModeOS, command); err != nil {
|
sourcev1.GitRepositoryKind,
|
||||||
return fmt.Errorf("uninstall failed")
|
sourcev1.HelmRepositoryKind,
|
||||||
|
} {
|
||||||
|
command := fmt.Sprintf("kubectl -n %s delete %s --all --timeout=%s %s",
|
||||||
|
namespace, kind, timeout.String(), dryRun)
|
||||||
|
if _, err := utils.execCommand(ctx, ModeOS, command); err != nil {
|
||||||
|
return fmt.Errorf("uninstall failed")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: use the kustomizations snapshots to create a list of objects
|
|
||||||
// that are subject to deletion and wait for all of them to be terminated
|
|
||||||
logger.Waitingf("waiting on GC")
|
|
||||||
time.Sleep(30 * time.Second)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
kinds := "namespace,clusterroles,clusterrolebindings"
|
kinds := "namespace,clusterroles,clusterrolebindings"
|
||||||
|
|||||||
@@ -166,3 +166,12 @@ func (*Utils) copyFile(src, dst string) error {
|
|||||||
}
|
}
|
||||||
return out.Close()
|
return out.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (*Utils) containsItemString(s []string, e string) bool {
|
||||||
|
for _, a := range s {
|
||||||
|
if a == e {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,9 +9,11 @@ The bootstrap sub-commands bootstrap the toolkit components on the targeted Git
|
|||||||
### Options
|
### Options
|
||||||
|
|
||||||
```
|
```
|
||||||
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller,helm-controller,notification-controller])
|
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller,helm-controller,notification-controller])
|
||||||
-h, --help help for bootstrap
|
-h, --help help for bootstrap
|
||||||
-v, --version string toolkit version (default "latest")
|
--image-pull-secret string Kubernetes secret name used for pulling the toolkit images from a private registry
|
||||||
|
--registry string container registry where the toolkit images are published (default "docker.io/fluxcd")
|
||||||
|
-v, --version string toolkit version (default "latest")
|
||||||
```
|
```
|
||||||
|
|
||||||
### Options inherited from parent commands
|
### Options inherited from parent commands
|
||||||
|
|||||||
@@ -54,12 +54,14 @@ tk bootstrap github [flags]
|
|||||||
### Options inherited from parent commands
|
### Options inherited from parent commands
|
||||||
|
|
||||||
```
|
```
|
||||||
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller,helm-controller,notification-controller])
|
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller,helm-controller,notification-controller])
|
||||||
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
|
--image-pull-secret string Kubernetes secret name used for pulling the toolkit images from a private registry
|
||||||
--namespace string the namespace scope for this operation (default "gitops-system")
|
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
|
||||||
--timeout duration timeout for this operation (default 5m0s)
|
--namespace string the namespace scope for this operation (default "gitops-system")
|
||||||
--verbose print generated objects
|
--registry string container registry where the toolkit images are published (default "docker.io/fluxcd")
|
||||||
-v, --version string toolkit version (default "latest")
|
--timeout duration timeout for this operation (default 5m0s)
|
||||||
|
--verbose print generated objects
|
||||||
|
-v, --version string toolkit version (default "latest")
|
||||||
```
|
```
|
||||||
|
|
||||||
### SEE ALSO
|
### SEE ALSO
|
||||||
|
|||||||
@@ -50,12 +50,14 @@ tk bootstrap gitlab [flags]
|
|||||||
### Options inherited from parent commands
|
### Options inherited from parent commands
|
||||||
|
|
||||||
```
|
```
|
||||||
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller,helm-controller,notification-controller])
|
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller,helm-controller,notification-controller])
|
||||||
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
|
--image-pull-secret string Kubernetes secret name used for pulling the toolkit images from a private registry
|
||||||
--namespace string the namespace scope for this operation (default "gitops-system")
|
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
|
||||||
--timeout duration timeout for this operation (default 5m0s)
|
--namespace string the namespace scope for this operation (default "gitops-system")
|
||||||
--verbose print generated objects
|
--registry string container registry where the toolkit images are published (default "docker.io/fluxcd")
|
||||||
-v, --version string toolkit version (default "latest")
|
--timeout duration timeout for this operation (default 5m0s)
|
||||||
|
--verbose print generated objects
|
||||||
|
-v, --version string toolkit version (default "latest")
|
||||||
```
|
```
|
||||||
|
|
||||||
### SEE ALSO
|
### SEE ALSO
|
||||||
|
|||||||
@@ -31,12 +31,14 @@ tk install [flags]
|
|||||||
### Options
|
### Options
|
||||||
|
|
||||||
```
|
```
|
||||||
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller,helm-controller,notification-controller])
|
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller,helm-controller,notification-controller])
|
||||||
--dry-run only print the object that would be applied
|
--dry-run only print the object that would be applied
|
||||||
--export write the install manifests to stdout and exit
|
--export write the install manifests to stdout and exit
|
||||||
-h, --help help for install
|
-h, --help help for install
|
||||||
--manifests string path to the manifest directory, dev only
|
--image-pull-secret string Kubernetes secret name used for pulling the toolkit images from a private registry
|
||||||
-v, --version string toolkit version (default "latest")
|
--manifests string path to the manifest directory, dev only
|
||||||
|
--registry string container registry where the toolkit images are published (default "docker.io/fluxcd")
|
||||||
|
-v, --version string toolkit version (default "latest")
|
||||||
```
|
```
|
||||||
|
|
||||||
### Options inherited from parent commands
|
### Options inherited from parent commands
|
||||||
|
|||||||
@@ -17,18 +17,18 @@ tk uninstall [flags]
|
|||||||
tk uninstall --dry-run --namespace=gitops-system
|
tk uninstall --dry-run --namespace=gitops-system
|
||||||
|
|
||||||
# Uninstall all components and delete custom resource definitions
|
# Uninstall all components and delete custom resource definitions
|
||||||
tk uninstall --crds --namespace=gitops-system
|
tk uninstall --resources --crds --namespace=gitops-system
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
```
|
```
|
||||||
--crds removes all CRDs previously installed
|
--crds removes all CRDs previously installed
|
||||||
--dry-run only print the object that would be deleted
|
--dry-run only print the object that would be deleted
|
||||||
-h, --help help for uninstall
|
-h, --help help for uninstall
|
||||||
--kustomizations removes all Kustomizations previously installed
|
--resources removes custom resources such as Kustomizations, GitRepositories and HelmRepositories
|
||||||
-s, --silent delete components without asking for confirmation
|
-s, --silent delete components without asking for confirmation
|
||||||
```
|
```
|
||||||
|
|
||||||
### Options inherited from parent commands
|
### Options inherited from parent commands
|
||||||
|
|||||||
173
docs/guides/sealed-secrets.md
Normal file
173
docs/guides/sealed-secrets.md
Normal file
@@ -0,0 +1,173 @@
|
|||||||
|
# Sealed Secrets
|
||||||
|
|
||||||
|
In order to store secrets safely in a public or private Git repository, you can use
|
||||||
|
Bitnami's [sealed-secrets controller](https://github.com/bitnami-labs/sealed-secrets)
|
||||||
|
and encrypt your Kubernetes Secrets into SealedSecrets.
|
||||||
|
The sealed secrets can be decrypted only by the controller running in your cluster and
|
||||||
|
nobody else can obtain the original secret, even if they have access to the Git repository.
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
|
||||||
|
To follow this guide you'll need a Kubernetes cluster with the GitOps
|
||||||
|
toolkit controllers installed on it.
|
||||||
|
Please see the [get started guide](../get-started/index.md)
|
||||||
|
or the [install command docs](../cmd/tk_install.md).
|
||||||
|
|
||||||
|
The sealed-secrets controller comes with a companion CLI tool called kubeseal.
|
||||||
|
With kubeseal you can create SealedSecret custom resources in YAML format
|
||||||
|
and store those in your Git repository.
|
||||||
|
|
||||||
|
Install the kubeseal CLI:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
brew install kubeseal
|
||||||
|
```
|
||||||
|
|
||||||
|
For Linux or Windows you can download the kubeseal binary from
|
||||||
|
[GitHub](https://github.com/bitnami-labs/sealed-secrets/releases).
|
||||||
|
|
||||||
|
## Deploy sealed-secrets with a HelmRelease
|
||||||
|
|
||||||
|
You'll be using [helm-controller](../components/helm/controller.md) APIs to install
|
||||||
|
the sealed-secrets controller from its [Helm chart](https://hub.kubeapps.com/charts/stable/sealed-secrets).
|
||||||
|
|
||||||
|
First you have to register the Helm repository where the sealed-secrets chart is published:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
tk create source helm stable \
|
||||||
|
--interval=1h \
|
||||||
|
--url=https://kubernetes-charts.storage.googleapis.com
|
||||||
|
```
|
||||||
|
|
||||||
|
With `interval` we configure [source-controller](../components/source/controller.md) to download
|
||||||
|
the Helm repository index every hour. If a newer version of sealed-secrets is published,
|
||||||
|
source-controller will signal helm-controller that a new chart is available.
|
||||||
|
|
||||||
|
Create a Helm release that installs the latest version of sealed-secrets controller:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
tk create helmrelease sealed-secrets \
|
||||||
|
--interval=1h \
|
||||||
|
--release-name=sealed-secrets \
|
||||||
|
--target-namespace=gitops-system \
|
||||||
|
--source=stable \
|
||||||
|
--chart-name=sealed-secrets \
|
||||||
|
--chart-version="^1.10.0"
|
||||||
|
```
|
||||||
|
|
||||||
|
With chart version `^1.10.0` we configure helm-controller to automatically upgrade the release
|
||||||
|
when a new chart version is fetch by source-controller.
|
||||||
|
|
||||||
|
At startup, the sealed-secrets controller generates a 4096-bit RSA key pair and
|
||||||
|
persists the private and public keys as Kubernetes secrets in the `gitops-system` namespace.
|
||||||
|
|
||||||
|
You can retrieve the public key with:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
kubeseal --fetch-cert \
|
||||||
|
--controller-name=sealed-secrets \
|
||||||
|
--controller-namespace=gitops-system \
|
||||||
|
> pub-sealed-secrets.pem
|
||||||
|
```
|
||||||
|
|
||||||
|
The public key can be safely stored in Git, and can be used to encrypt secrets
|
||||||
|
without direct access to the Kubernetes cluster.
|
||||||
|
|
||||||
|
## Encrypt secrets
|
||||||
|
|
||||||
|
Generate a Kubernetes secret manifest with kubectl:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
kubectl -n default create secret generic basic-auth \
|
||||||
|
--from-literal=user=admin \
|
||||||
|
--from-literal=password=change-me \
|
||||||
|
--dry-run \
|
||||||
|
-o yaml > basic-auth.yaml
|
||||||
|
```
|
||||||
|
|
||||||
|
Encrypt the secret with kubeseal:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
kubeseal --format=yaml --cert=pub-sealed-secrets.pem \
|
||||||
|
< basic-auth.yaml > basic-auth-sealed.yaml
|
||||||
|
```
|
||||||
|
|
||||||
|
Delete the plain secret and apply the sealed one:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
rm basic-auth.yaml
|
||||||
|
kubectl apply -f basic-auth-sealed.yaml
|
||||||
|
```
|
||||||
|
|
||||||
|
Verify that the sealed-secrets controller has created the `basic-auth` Kubernetes Secret:
|
||||||
|
|
||||||
|
```console
|
||||||
|
$ kubectl -n default get secrets basic-auth
|
||||||
|
|
||||||
|
NAME TYPE DATA AGE
|
||||||
|
basic-auth Opaque 2 1m43s
|
||||||
|
```
|
||||||
|
|
||||||
|
## GitOps workflow
|
||||||
|
|
||||||
|
A cluster admin should add the stable `HelmRepository` manifest and the sealed-secrets `HelmRelease`
|
||||||
|
to the fleet repository.
|
||||||
|
|
||||||
|
Helm repository manifest:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
apiVersion: source.fluxcd.io/v1alpha1
|
||||||
|
kind: HelmRepository
|
||||||
|
metadata:
|
||||||
|
name: stable
|
||||||
|
namespace: gitops-system
|
||||||
|
spec:
|
||||||
|
interval: 1h0m0s
|
||||||
|
url: https://kubernetes-charts.storage.googleapis.com
|
||||||
|
```
|
||||||
|
|
||||||
|
Helm release manifest:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
apiVersion: helm.fluxcd.io/v2alpha1
|
||||||
|
kind: HelmRelease
|
||||||
|
metadata:
|
||||||
|
name: sealed-secrets
|
||||||
|
namespace: gitops-system
|
||||||
|
spec:
|
||||||
|
chart:
|
||||||
|
name: sealed-secrets
|
||||||
|
sourceRef:
|
||||||
|
kind: HelmRepository
|
||||||
|
name: stable
|
||||||
|
version: "^1.10.0"
|
||||||
|
interval: 1h0m0s
|
||||||
|
releaseName: sealed-secrets
|
||||||
|
targetNamespace: gitops-system
|
||||||
|
```
|
||||||
|
|
||||||
|
!!! hint
|
||||||
|
You can generate the above manifests using `tk create <kind> --export > manifest.yaml`.
|
||||||
|
|
||||||
|
Once the sealed-secrets controller is installed, the admin fetches the
|
||||||
|
public key and shares it with the teams that operate on the fleet clusters via Git.
|
||||||
|
|
||||||
|
When a team member wants to create a Kubernetes Secret on a cluster,
|
||||||
|
they uses kubeseal and the public key corresponding to that cluster to generate a SealedSecret.
|
||||||
|
|
||||||
|
Assuming a team member wants to deploy an application that needs to connect
|
||||||
|
to a database using a username and password, they'll be doing the following:
|
||||||
|
|
||||||
|
* create a Kubernetes Secret manifest locally with the db credentials e.g. `db-auth.yaml`
|
||||||
|
* encrypt the secret with kubeseal as `db-auth-sealed.yaml`
|
||||||
|
* delete the original secret file `db-auth.yaml`
|
||||||
|
* create a Kubernetes Deployment manifest for the app e.g. `app-deployment.yaml`
|
||||||
|
* add the Secret to the Deployment manifest as a [volume mount or env var](https://kubernetes.io/docs/concepts/configuration/secret/#using-secrets) using the original name `db-auth`
|
||||||
|
* commit the manifests `db-auth-sealed.yaml` and `app-deployment.yaml` to a Git repository that's being synced by the GitOps toolkit controllers
|
||||||
|
|
||||||
|
Once the manifests have been pushed to the Git repository, the following happens:
|
||||||
|
|
||||||
|
* source-controller pulls the changes from Git
|
||||||
|
* kustomize-controller applies the SealedSecret and the Deployment manifests
|
||||||
|
* sealed-secrets controller decrypts the SealedSecret and creates a Kubernetes Secret
|
||||||
|
* kubelet creates the pods and mounts the secret as a volume or env variable inside the app container
|
||||||
2
go.mod
2
go.mod
@@ -4,7 +4,7 @@ go 1.14
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/blang/semver v3.5.1+incompatible
|
github.com/blang/semver v3.5.1+incompatible
|
||||||
github.com/fluxcd/helm-controller v0.0.1-beta.3
|
github.com/fluxcd/helm-controller v0.0.1-beta.4
|
||||||
github.com/fluxcd/kustomize-controller v0.0.5
|
github.com/fluxcd/kustomize-controller v0.0.5
|
||||||
github.com/fluxcd/pkg v0.0.3
|
github.com/fluxcd/pkg v0.0.3
|
||||||
github.com/fluxcd/source-controller v0.0.6
|
github.com/fluxcd/source-controller v0.0.6
|
||||||
|
|||||||
4
go.sum
4
go.sum
@@ -172,8 +172,8 @@ github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d h1:105gxyaGwC
|
|||||||
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d/go.mod h1:ZZMPRZwes7CROmyNKgQzC3XPs6L/G2EJLHddWejkmf4=
|
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d/go.mod h1:ZZMPRZwes7CROmyNKgQzC3XPs6L/G2EJLHddWejkmf4=
|
||||||
github.com/fatih/camelcase v1.0.0/go.mod h1:yN2Sb0lFhZJUdVvtELVWefmrXpuZESvPmqwoZc+/fpc=
|
github.com/fatih/camelcase v1.0.0/go.mod h1:yN2Sb0lFhZJUdVvtELVWefmrXpuZESvPmqwoZc+/fpc=
|
||||||
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||||
github.com/fluxcd/helm-controller v0.0.1-beta.3 h1:S6XOwAM0IbJxYDbasv85Zk7W1gJ51S3ZqYylMtGcuEE=
|
github.com/fluxcd/helm-controller v0.0.1-beta.4 h1:Go7ZGI91BY6A69Qp9TdJg3nufaahQCYhpj7Lum9oyKA=
|
||||||
github.com/fluxcd/helm-controller v0.0.1-beta.3/go.mod h1:asoN9pG8J0oQ9iXpkxNwvch1EKspus6RxH818ZYVo+4=
|
github.com/fluxcd/helm-controller v0.0.1-beta.4/go.mod h1:asoN9pG8J0oQ9iXpkxNwvch1EKspus6RxH818ZYVo+4=
|
||||||
github.com/fluxcd/kustomize-controller v0.0.5 h1:jjBJT/UbblMaeQpYn5TjH/oXXnORO6C3Cka77bs9K3Q=
|
github.com/fluxcd/kustomize-controller v0.0.5 h1:jjBJT/UbblMaeQpYn5TjH/oXXnORO6C3Cka77bs9K3Q=
|
||||||
github.com/fluxcd/kustomize-controller v0.0.5/go.mod h1:1O78f9Qigs74BMxO/ThzLt5XGGQnwQPgzi+47ntie5M=
|
github.com/fluxcd/kustomize-controller v0.0.5/go.mod h1:1O78f9Qigs74BMxO/ThzLt5XGGQnwQPgzi+47ntie5M=
|
||||||
github.com/fluxcd/pkg v0.0.3 h1:yhjtpGtD9LxFo8JtwTuUxJyFcX2wSSb0TPptIEpGSmA=
|
github.com/fluxcd/pkg v0.0.3 h1:yhjtpGtD9LxFo8JtwTuUxJyFcX2wSSb0TPptIEpGSmA=
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
kind: Kustomization
|
kind: Kustomization
|
||||||
resources:
|
resources:
|
||||||
- github.com/fluxcd/helm-controller/config//crd?ref=v0.0.1-beta.3
|
- github.com/fluxcd/helm-controller/config//crd?ref=v0.0.1-beta.4
|
||||||
- github.com/fluxcd/helm-controller/config//manager?ref=v0.0.1-beta.3
|
- github.com/fluxcd/helm-controller/config//manager?ref=v0.0.1-beta.4
|
||||||
patchesJson6902:
|
patchesJson6902:
|
||||||
- target:
|
- target:
|
||||||
group: apps
|
group: apps
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
kind: Kustomization
|
kind: Kustomization
|
||||||
resources:
|
resources:
|
||||||
- github.com/fluxcd/kustomize-controller/config//crd?ref=v0.0.5
|
- github.com/fluxcd/kustomize-controller/config//crd?ref=v0.0.6
|
||||||
- github.com/fluxcd/kustomize-controller/config//manager?ref=v0.0.5
|
- github.com/fluxcd/kustomize-controller/config//manager?ref=v0.0.6
|
||||||
patchesJson6902:
|
patchesJson6902:
|
||||||
- target:
|
- target:
|
||||||
group: apps
|
group: apps
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ nav:
|
|||||||
- Manage Helm Releases: guides/helmreleases.md
|
- Manage Helm Releases: guides/helmreleases.md
|
||||||
- Setup Notifications: guides/notifications.md
|
- Setup Notifications: guides/notifications.md
|
||||||
- Setup Webhook Receivers: guides/webhook-receivers.md
|
- Setup Webhook Receivers: guides/webhook-receivers.md
|
||||||
|
- Sealed Secrets: guides/sealed-secrets.md
|
||||||
- Toolkit Components:
|
- Toolkit Components:
|
||||||
- Source Controller:
|
- Source Controller:
|
||||||
- Overview: components/source/controller.md
|
- Overview: components/source/controller.md
|
||||||
|
|||||||
Reference in New Issue
Block a user