cloudflare

This commit is contained in:
Tomás Limpinho
2025-11-12 17:18:40 +00:00
parent ebd772665b
commit 6c78b7ce39
5 changed files with 116 additions and 0 deletions

View File

@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: cloudflare

View File

@ -0,0 +1,49 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: cloudflared-tunnel
namespace: cloudflare
spec:
replicas: 3
selector:
matchLabels:
app: cloudflared
template:
metadata:
labels:
app: cloudflared
spec:
securityContext:
sysctls:
# Allows ICMP traffic (ping, traceroute) to resources behind cloudflared.
- name: net.ipv4.ping_group_range
value: "65532 65532"
containers:
- image: cloudflare/cloudflared:latest
name: cloudflared
env:
# Defines an environment variable for the tunnel token.
- name: TUNNEL_TOKEN
valueFrom:
secretKeyRef:
name: tunnel-token-secret
key: token
command:
# Configures tunnel run parameters
- cloudflared
- tunnel
- --no-autoupdate
- --loglevel
- debug
- --metrics
- 0.0.0.0:2000
- run
livenessProbe:
httpGet:
# Cloudflared has a /ready endpoint which returns 200 if and only if
# it has an active connection to Cloudflare's network.
path: /ready
port: 2000
failureThreshold: 1
initialDelaySeconds: 10
periodSeconds: 10

View File

@ -0,0 +1,8 @@
apiVersion: v1
kind: Secret
metadata:
name: tunnel-token-secret
namespace: cloudflare
type: Opaque
data:
token: <CLOUDFLARE_TUNNEL_TOKEN>

View File

@ -0,0 +1,51 @@
- name: Remover o diretório /tmp/cloudflare/kubernetes-files
ansible.builtin.file:
path: /tmp/cloudflare/kubernetes-files
state: absent
- name: Criar diretório temporário no remoto
file:
path: /tmp/cloudflare/kubernetes-files
state: directory
mode: '0755'
- name: Copy file with owner and permissions
ansible.builtin.copy:
src: ../files
dest: /tmp/cloudflare/kubernetes-files
owner: fenix
group: root
mode: '0644'
- name: Obter várias notas do Bitwarden
shell: |
echo "unlock"
BW_SESSION=$(bw unlock {{ bw_password }} --raw)
echo "get item"
bw get item "{{ item.id }}" --session $BW_SESSION | jq -r '.notes' > {{ item.dest }}
loop:
- { id: "iac.ansible.cloudflare.tunnel.secret", dest: "/tmp/cloudflare/kubernetes-files/files/tunnel-token-secret.yaml" }
args:
executable: /bin/bash
environment:
BW_PASSWORD: "{{ BW_PASSWORD }}"
- name: Listar conteúdo do diretório remoto
shell: ls -l /tmp/cloudflare/kubernetes-files/files
register: resultado_ls
- name: Mostrar resultado do ls
debug:
var: resultado_ls.stdout_lines
- name: Aplicar o stolon
become: yes
become_user: fenix
shell: |
kubectl apply -f /tmp/cloudflare/kubernetes-files/files/
environment:
KUBECONFIG: /home/fenix/.kube/config

View File

@ -0,0 +1,4 @@
bw_password: "{{ lookup('env', 'BW_PASSWORD') }}"
VAULTWARDEN_LINK: "{{ lookup('env', 'VAULTWARDEN_LINK') }}"
BW_CLIENTID: "{{ lookup('env', 'BW_CLIENTID') }}"
BW_CLIENTSECRET : "{{ lookup('env', 'BW_CLIENTSECRET') }}"