This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from simonostendorf/dev
Fix/readme and script (#28)
- Loading branch information
Showing
3 changed files
with
70 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |