Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #29 from simonostendorf/dev
Browse files Browse the repository at this point in the history
Fix/readme and script (#28)
  • Loading branch information
TitusKirch authored Oct 1, 2022
2 parents ffc401e + 8b2831c commit 1dc801a
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ This repository only holds the code for the documentation and deployments.
[![GitHub release](https://img.shields.io/github/release/simonostendorf/k3s-hetzner?include_prereleases=&sort=semver&color=blue)](https://github.com/simonostendorf/k3s-hetzner/releases/)

### license
[![License](https://img.shields.io/badge/License-MIT-blue)](#license)
[![License](https://img.shields.io/badge/License-CC--BY--SA--4.0%20license-blue)](#license)

### issues
[![issues - k3s-hetzner](https://img.shields.io/github/issues/simonostendorf/k3s-hetzner)](https://github.com/simonostendorf/k3s-hetzner/issues)
Expand All @@ -35,7 +35,7 @@ Be shure to read the [contribution guidelines](CONTRIBUTING.md) and the [code of
## License

Copyright © 2020 Simon Ostendorf
This project is licensed under the [MIT License](LICENSE).
This project is licensed under the [CC-BY-4.0 license](LICENSE).

## Credits
Huge thank you to many people and git repos where I got my information and commands from.
Expand Down
29 changes: 29 additions & 0 deletions docs/prerequisites/container-registry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Container Registry
To provide docker container images for the cluster you will need a container registry.
In this example i will use the [docker-hub](https://hub.docker.com/) but feel free to use other platforms like [github-container-registry](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry) or something else.

## Create Account
First, create an account at your container-registry provider. If you already have one, you can skip this step.
If you want to use a docker-hub account, you can register [here](https://hub.docker.com/signup).

<img src="../../assets/prerequisites/container-repository/create-account.png" width=40%>

## Create Token
To access the registry and push or pull images (pull only of you use private images) you will need a token.

If you use the docker-hub, move to your [security-profile-page](https://hub.docker.com/settings/security) for the token creation.
The names of the tokens are not important, but you should know which token is for which purpose.

!!! note "Reminder"
Be shure to save the token in a save place because you need it later in the setup.
The token is only shown once.

You will need to create the following tokens:

* `local-machine` with **write-access** used for your local machine to push the created images

If you want to use private images you also need to create a token for the cluster to pull the images:

* `k8s-hetzner` with **read-access** used on the kubernetes hosts to pull the images from the container registry

<img src="../../assets/prerequisites/container-repository/create-token.png" width=60%>
39 changes: 39 additions & 0 deletions scripts/setup-agent-nodes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import argparse
from hcloud import Client

def find_used_ips(network, ip_begin):
max_ip = 0
for srv in network.data_model.servers:
server_id = srv.data_model.id
server_obj = client.servers.get_by_id(server_id)
private_net = server_obj.data_model.private_net[0]

if private_net.ip.startswith(ip_begin):
curr_ip = int(private_net.ip.split('.')[3])
if curr_ip > max_ip:
max_ip = curr_ip
return max_ip

parser = argparse.ArgumentParser()

parser.add_argument('--token', help='Hetzner Cloud API Token', required=True)
parser.add_argument('--server_name', help='Server Name', required=True)
parser.add_argument('--network_id', help='Private Network ID', required=True)

args = parser.parse_args()

client = Client(token=args.token)

server = client.servers.get_by_name(args.server_name)

network = client.networks.get_by_id(args.network_id)

if server.data_model.datacenter.location.name == "hel1":
max_ip = find_used_ips(network, "10.2.0.")
server.attach_to_network(network=client.networks.get_by_id(args.network_id), ip="10.2.0." + str(max_ip + 1))
elif server.data_model.datacenter.location.name == "fsn1":
max_ip = find_used_ips(network, "10.2.1.")
server.attach_to_network(network=client.networks.get_by_id(args.network_id), ip="10.2.1." + str(max_ip + 1))
elif server.data_model.datacenter.location.name == "nbg1":
max_ip = find_used_ips(network, "10.2.2.")
server.attach_to_network(network=client.networks.get_by_id(args.network_id), ip="10.2.2." + str(max_ip + 1))

0 comments on commit 1dc801a

Please sign in to comment.