kubernetes-cloudflare-ddns

by Kubito

Helm chartv1.0.6App 1.0.1Verified publisher

Kubito Kubernetes Cloudflare DDNS Helm Chart

About this chart

Kubernetes Cloudflare DDNS

A simple Kubernetes cronjob which can be used for updating a DNS record on Cloudflare.

TL;DR

helm repo add kubitodev https://charts.kubito.dev
helm install kubernetes-cloudflare-ddns kubitodev/kubernetes-cloudflare-ddns

Introduction

This chart can be used to solve the problem of a Kubernetes cluster being behind a Dynamic IP address and you need to configure a load balancer to run behind it. It is a good solution for home labs and similar setups.

Prerequisites

  • Kubernetes 1.12+
  • Helm 3.2.0+

Installing the Chart

To install the chart with the release name kubernetes-cloudflare-ddns:

helm install kubernetes-cloudflare-ddns kubitodev/kubernetes-cloudflare-ddns

The command deploys kubernetes-cloudflare-ddns on the Kubernetes cluster in the default configuration. The Parameters section lists the parameters that can be configured during installation.

Tip: List all releases using helm list

Uninstalling the Chart

To uninstall/delete the kubernetes-cloudflare-ddns deployment:

helm delete kubernetes-cloudflare-ddns

The command removes all the Kubernetes components associated with the chart and deletes the release.

Parameters

Image parameters

NameDescriptionValue
image.repositoryThe Docker repository to pull the image from.kubitodev/kubernetes-cloudflare-ddns
image.tagThe image tag to use.1.0.1

Cron parameters

NameDescriptionValue
cron.job.scheduleInterval for how often the job should run."*/5 * * * *"
cron.job.successfulJobsHistoryLimitLimit of the successful jobs saved in history as completed pods.1
cron.pod.restartPolicyThe logic for restarting the cron pod.OnFailure

Secret parameters

NameDescriptionValue
secret.existingSecretName of an existing secret. Check secret.yaml for the required variables.""
secret.authKeyThe value of your Cloudflare API Key.""
secret.dnsRecordThe A record you want to update.""
secret.recordIdThe ID of the record you are updating.""
secret.zoneIdThe zone ID of your domain.""

Specify each parameter using the --set key=value[,key=value] argument to helm install. For example,

helm install example \
  --set user=example \
  --set password=example \
    kubitodev/example

Alternatively, a YAML file that specifies the values for the above parameters can be provided while installing the chart. For example,

helm install example -f values.yaml kubitodev/example

Tip: You can use the default values.yaml

Configuration and installation details

Getting the API Key

Login to Cloudflare and create an API key for your domain on Cloudflare with the following settings:

Token Name: `Edit Zone DNS`.
Permissions: `Zone -> DNS -> Edit`.
Zone Resources: `Include -> All zones`.
Client API Filtering can be left as default.
TTL can be left as default.

Getting the Zone ID

Go to the overview tab on Cloudflare for your domain and copy the Zone ID key.

Getting the Record ID

Now you need to get the record ID for the A record that you wish to update. To do so, just execute the following command where you will replace the variables with your own:

export ZONE_ID=<YOUR_ZONE_ID>
export AUTH_KEY=<YOUR_API_KEY>

curl -X GET "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records?type=A" \
     -H "X-Auth-Email: [email protected]" \
     -H "Authorization: Bearer $AUTH_KEY" \
     -H "Content-Type: application/json"

You will get a JSON object returned, and you can use a prettifier or something to get a better look at it if you wish. When you see the record that you want, copy the id field value.

License

Copyright © 2022 Kubito

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Deploy kubernetes-cloudflare-ddns with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has kubernetes-cloudflare-ddns on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartkubernetes-cloudflare-ddns is pinned at v1.0.6 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply