Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor chart #86

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
on:
workflow_dispatch:
pull_request:

jobs:
e2e:
name: e2e
runs-on: self-hosted
steps:
- uses: actions/setup-go@v2
with:
go-version: '1.21'
- uses: actions/checkout@v2
- run: make e2e branch=$GITHUB_HEAD_REF
11 changes: 7 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
KUBECONFIG=$(HOME)/.kube/hcloud
action=list-configurations
config=config.yaml
fullConfig=./examples/config-full.yaml
fullConfig=./e2e/configs/full.yaml
args=""
branch=`git rev-parse --abbrev-ref HEAD`

test:
./scripts/validate-license.sh
go fmt ./cmd/... ./pkg/...
go mod tidy
go run github.com/golangci/golangci-lint/cmd/golangci-lint@latest run -v
CONFIG=config_test.yaml go test -race -coverprofile coverage.out ./cmd/... ./pkg/...
.PHONY: e2e
e2e:
GIT_BRANCH=$(branch) go test -v -count=1 -timeout=4h ./e2e/e2e_test.go
update-readme:
go run ./utils/main.go
coverage:
go tool cover -html=coverage.out
create-cluster:
Expand Down Expand Up @@ -49,9 +55,6 @@ test-kubernetes-yaml:
helm lint ./examples/charts/test --values=$(fullConfig)
helm template ./scripts/chart --values=$(fullConfig) | kubectl apply --dry-run=client --validate=true -f -
helm template ./examples/charts/test --values=$(fullConfig) | kubectl apply --dry-run=client --validate=true -f -
download-yamls:
curl -sSL -o ./scripts/chart/templates/kube-flannel.yml https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
curl -sSL -o ./scripts/chart/templates/metrics-server.yml https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
install:
go run github.com/goreleaser/goreleaser@latest build \
--single-target \
Expand Down
179 changes: 170 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ for other OS download binnary from [release pages](https://github.com/maksim-pas

This will create kubernetes cluster in Hetzner Cloud Europe region with 3 instances, 1 load balancer for the kubernetes control plane and 1 kubernetes worker node, after successful installation the cluster will have:

- [Kubernetes v1.24](https://github.com/kubernetes/kubernetes)
- [Kubernetes v1.28](https://github.com/kubernetes/kubernetes)
- [Kubernetes Autoscaler](https://github.com/kubernetes/autoscaler)
- [Flannel](https://github.com/flannel-io/flannel)
- [Kubernetes Cloud Controller Manager for Hetzner Cloud](https://github.com/hetznercloud/hcloud-cloud-controller-manager)
Expand All @@ -36,7 +36,7 @@ This will create kubernetes cluster in Hetzner Cloud Europe region with 3 instan

for HA needs odd number of master nodes (minimum 3) <https://etcd.io/docs/v3.4/faq/#why-an-odd-number-of-cluster-members>

create a simple configuration file `config.yaml` full configuration example [here](https://github.com/maksim-paskal/hcloud-k8s-ctl/blob/main/examples/config-full.yaml)
Create a simple configuration file `config.yaml` full configuration example [here](https://github.com/maksim-paskal/hcloud-k8s-ctl/blob/main/e2e/configs/full.yaml)

```yaml
# kubeconfig path
Expand All @@ -49,22 +49,183 @@ ipRange: "10.0.0.0/16"
masterCount: 3
```

to create kubernetes cluster in Hetzner Cloud US region append to `config.yaml` next lines
customize configuration file for your needs

```yaml
# kubeconfig path
kubeConfigPath: ~/.kube/hcloud
# Hetzner cloud internal network CIDR
ipRange: "10.0.0.0/16"
# servers for kubernetes master (recommended 3)
# for development purposes cluster can have 1 master node
# in this case cluster will be created without load balancer and pods can schedule on master
masterCount: 3
# server components for all nodes in cluster
serverComponents:
kubernetes:
# customize kubertenes version
version: 1.25.14
docker:
# customize apt package version for docker install
# apt-cache madison docker-ce
version: 5:24.0.6-1~ubuntu.20.04~focal
containerd:
# customize apt package version for containerd install
# apt-cache madison containerd.io
version: 1.6.24-1
# add autoscaler chart extra values
cluster-autoscaler:
replicaCount: 3
resources:
requests:
cpu: 200m
memory: 300Mi
# add some custom script for all nodes in cluster
preStartScript: |
# add some custom cron job on node
crontab <<EOF
0 0 * * * /usr/bin/docker system prune -af
EOF

# add containerd config for some registries
mkdir -p /etc/containerd/certs.d/some-registry.io
cat > /etc/containerd/certs.d/some-registry.io/hosts.toml <<EOF
server = "https://some-registry.io"

[host."http://10.10.10.10:5000"]
capabilities = ["pull", "resolve"]
EOF
```

<!--- move_e2e_details_start -->
<details><summary>Kubernetes v1.25 in Europe</summary>

```yaml
ipRange: "10.0.0.0/16"
masterCount: 3
serverComponents:
kubernetes:
version: 1.25.14
docker:
version: 5:24.0.6-1~ubuntu.20.04~focal
containerd:
version: 1.6.24-1
cluster-autoscaler:
replicaCount: 3
resources:
requests:
cpu: 100m
memory: 300Mi
preStartScript: |
# add some custom cron job on node
crontab <<EOF
0 0 * * * /usr/bin/docker system prune -af
EOF

# add containerd config for some registries
mkdir -p /etc/containerd/certs.d/some-registry.io
cat > /etc/containerd/certs.d/some-registry.io/hosts.toml <<EOF
server = "https://some-registry.io"

[host."http://10.10.10.10:5000"]
capabilities = ["pull", "resolve"]
EOF
```
</details>
<details><summary>Kubernetes v1.26 in Europe</summary>

```yaml
ipRange: "10.0.0.0/16"
masterCount: 3
serverComponents:
kubernetes:
version: 1.26.9
docker:
version: 5:24.0.6-1~ubuntu.20.04~focal
containerd:
version: 1.6.24-1

```
</details>
<details><summary>Kubernetes v1.27 in Europe</summary>

```yaml
ipRange: "10.0.0.0/16"
masterCount: 3
serverComponents:
kubernetes:
version: 1.27.6
docker:
version: 5:24.0.6-1~ubuntu.20.04~focal
containerd:
version: 1.6.24-1

```
</details>
<details><summary>Kubernetes v1.28 in Europe</summary>

```yaml
ipRange: "10.0.0.0/16"
masterCount: 3
serverComponents:
kubernetes:
version: 1.28.2
docker:
version: 5:24.0.6-1~ubuntu.20.04~focal
containerd:
version: 1.6.24-1

```
</details>
<details><summary>Kubernetes v1.28 in US East</summary>

```yaml
ipRange: "10.0.0.0/16"
masterCount: 3
networkZone: us-east
location: ash
datacenter: ash-dc1
masterServers:
servertype: cpx21
autoscaler:
workers:
- location: ash
type:
- cpx51
serverComponents:
kubernetes:
version: 1.28.2
docker:
version: 5:24.0.6-1~ubuntu.20.04~focal
containerd:
version: 1.6.24-1
cluster-autoscaler:
autoscalingGroups:
- name: CPX51:ASH:cpx51-ash
minSize: 1
maxSize: 20
```
</details>
<details><summary>Kubernetes v1.28 in Europe (ARM64 architecture)</summary>

```yaml
ipRange: "10.0.0.0/16"
masterCount: 3
serverComponents:
ubuntu:
architecture: arm
kubernetes:
version: 1.28.2
docker:
version: 5:24.0.6-1~ubuntu.20.04~focal
containerd:
version: 1.6.24-1
masterServers:
servertype: cax11
cluster-autoscaler:
autoscalingGroups:
- name: CAX41:FSN1:cax-fsn1
minSize: 1
maxSize: 20
```
</details>

and start application
<!--- move_e2e_details_end -->

```bash
# create 3 instance with 1 load balancer
Expand Down
11 changes: 7 additions & 4 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"syscall"
"time"

"github.com/maksim-paskal/hcloud-k8s-ctl/internal"
"github.com/maksim-paskal/hcloud-k8s-ctl/pkg/api"
"github.com/maksim-paskal/hcloud-k8s-ctl/pkg/config"
log "github.com/sirupsen/logrus"
Expand All @@ -47,7 +48,7 @@ func main() { //nolint:cyclop,funlen

log.SetReportCaller(true)

if err := config.Load(); err != nil {
if err := internal.Init(); err != nil {
log.WithError(err).Fatal("error loading config")
}

Expand All @@ -58,8 +59,6 @@ func main() { //nolint:cyclop,funlen

log.SetLevel(logLevel)

log.Infof("Loaded config:\n%s\n", config.String())

if err := config.Check(); err != nil {
log.WithError(err).Fatal("error checking config")
}
Expand All @@ -80,7 +79,10 @@ func main() { //nolint:cyclop,funlen
case "list-configurations":
applicationAPI.ListConfigurations(ctx)
case "patch-cluster":
applicationAPI.PatchClusterDeployment(ctx)
err = applicationAPI.PatchClusterDeployment(ctx)
if err != nil {
log.WithError(err).Fatal()
}
case "adhoc":
if len(*config.Get().CliArgs.AdhocCommand) == 0 {
log.Fatal("add -adhoc.command argument")
Expand Down Expand Up @@ -123,6 +125,7 @@ func getInterruptionContext() context.Context {

go func() {
<-c
log.Warn("Received interruption signal, stopping...")
cancel()

// wait 5s for graceful shutdown
Expand Down
Loading
Loading