Commit 33526956 authored by Sergio Gimenez's avatar Sergio Gimenez
Browse files

Add harbor

parent 1a9f79d4
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -17,12 +17,14 @@ kubernetes_version: v1.33.1
api_server_address: "0.0.0.0"
api_server_port: 6443
# External IP for kubeconfig (set to host IP for remote access)
external_host_ip: "192.168.123.188"
external_host_ip: "{{ host_ip }}"

# Service NodePorts
prometheus_nodeport: 30090
grafana_nodeport: 30091
alertmanager_nodeport: 30092
harbor_http_nodeport: 30002
harbor_https_nodeport: 30003
i2edge_nodeport: 30769

# Port mappings - using parameterized NodePorts to avoid duplication
@@ -43,6 +45,14 @@ port_mappings:
    host_port: "{{ alertmanager_nodeport }}"
    listen_address: "{{ api_server_address }}"
    protocol: TCP
  - container_port: "{{ harbor_http_nodeport }}"
    host_port: "{{ harbor_http_nodeport }}"
    listen_address: "{{ api_server_address }}"
    protocol: TCP
  - container_port: "{{ harbor_https_nodeport }}"
    host_port: "{{ harbor_https_nodeport }}"
    listen_address: "{{ api_server_address }}"
    protocol: TCP
  - container_port: "{{ i2edge_nodeport }}"
    host_port: "{{ i2edge_nodeport }}"
    listen_address: "{{ api_server_address }}"
+16 −0
Original line number Diff line number Diff line
@@ -16,6 +16,22 @@ all:
      ansible_python_interpreter: /usr/bin/python3
      deployment_mode: remote
      host_ip: 192.168.123.188
      kubeconfig_output_dir: "/home/ubuntu/kind-cluster-config"

    openop_2:
      ansible_host: openop-2
      ansible_connection: ssh
      ansible_user: ubuntu
      ansible_ssh_common_args: '-o StrictHostKeyChecking=no'
      ansible_python_interpreter: /usr/bin/python3
      deployment_mode: remote
      host_ip: 192.168.123.178
  
  children:
    kind_cluster:
      hosts:
        openop_dev_vm:  # Remote VM
        # localhost:  # Local deployment
  
  vars:
    # Kind cluster configuration
+32 −0
Original line number Diff line number Diff line
---
# Playbook: Deploy Harbor
# Description: Deploys Harbor artifact registry to the Kind cluster
# Usage: ansible-playbook playbooks/02-deploy-harbor.yml

- name: Deploy Harbor to Kind Cluster
  hosts: kind_cluster
  gather_facts: true
  
  pre_tasks:
    - name: Load group variables
      ansible.builtin.include_vars:
        file: "{{ playbook_dir }}/../group_vars/all.yml"

    - name: Set kubeconfig path for remote deployment
      ansible.builtin.set_fact:
        kubeconfig_output_dir: "/home/ubuntu/kind-cluster-config"
      when: inventory_hostname == 'openop_dev_vm'

  
    - name: Display playbook information
      ansible.builtin.debug:
        msg: |
          ==========================================
          Deploying Harbor Registry
          ==========================================
          Cluster: {{ kind_cluster_name }}
          ==========================================

  roles:
    - role: helm
    - role: harbor
+15 −0
Original line number Diff line number Diff line
---
# Harbor Helm settings
harbor_helm_repo_name: harbor
harbor_helm_repo_url: https://helm.goharbor.io
harbor_chart: harbor/harbor
harbor_release_name: harbor
harbor_namespace: harbor
harbor_install_timeout: 600

# Harbor configuration
harbor_admin_password: "Harbor12345"
harbor_persistence_enabled: true
harbor_storage_class: "standard"
harbor_expose_type: nodePort
harbor_external_url: "http://{{ external_host_ip }}:{{ harbor_http_nodeport }}"
+53 −0
Original line number Diff line number Diff line
---
# Tasks for installing Harbor

- name: Add Harbor Helm repository
  ansible.builtin.command: >
    helm repo add {{ harbor_helm_repo_name }} {{ harbor_helm_repo_url }}
  register: helm_repo_add
  changed_when: "'already exists' not in helm_repo_add.stderr"
  failed_when: helm_repo_add.rc != 0 and 'already exists' not in helm_repo_add.stderr

- name: Update Helm repositories
  ansible.builtin.command: helm repo update
  changed_when: false

- name: Create Harbor namespace
  ansible.builtin.shell: >
    kubectl create namespace {{ harbor_namespace }}
    --dry-run=client -o yaml | kubectl apply --kubeconfig {{ kubeconfig_output_dir }}/{{ kubeconfig_filename }} -f -
  environment:
    KUBECONFIG: "{{ kubeconfig_output_dir }}/{{ kubeconfig_filename }}"
  register: create_ns
  changed_when: "'created' in create_ns.stdout"



- name: Create Harbor values file from template
  ansible.builtin.template:
    src: harbor-values.yaml.j2
    dest: "{{ kubeconfig_output_dir }}/harbor-values.yaml"
    mode: '0644'

- name: Check if Harbor is already installed
  ansible.builtin.command: helm list -n {{ harbor_namespace }}
  register: helm_list
  changed_when: false
  environment:
    KUBECONFIG: "{{ kubeconfig_output_dir }}/{{ kubeconfig_filename }}"

- name: Install or upgrade Harbor
  ansible.builtin.command: >
    helm {{ 'upgrade' if harbor_release_name in helm_list.stdout else 'install' }}
    {{ harbor_release_name }}
    {{ harbor_chart }}
    -n {{ harbor_namespace }}
    -f {{ kubeconfig_output_dir }}/harbor-values.yaml
    --timeout {{ harbor_install_timeout }}s
  register: harbor_install
  environment:
    KUBECONFIG: "{{ kubeconfig_output_dir }}/{{ kubeconfig_filename }}"

- name: Display Harbor installation result
  ansible.builtin.debug:
    msg: " Harbor {{ 'upgraded' if 'upgrade' in harbor_install.cmd else 'installed' }} successfully"
Loading