| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- - name: TCP Configuration
- include_role:
- name: tcp
- - name: Include utils/controlplane tasks
- include_role:
- name: utils/controlplane
- - name: Get cluster token
- shell: /opt/yunion/bin/ocadm token list | cut -d ' ' -f1 | sed -n '2p'
- register: K8S_TOKEN
- - name: Verify online status
- ansible.builtin.debug:
- msg: Online status is {{ online_status }} and offline_data_path is {{ offline_data_path }}
- - name: loading images
- include_role:
- name: utils/load-images
- when:
- - online_status == "offline"
- - offline_data_path | length > 0
- - name: setup local registry
- include_role:
- name: registry
- when:
- - online_status == "offline"
- - offline_data_path | length > 0
- - docker_insecure_registries is defined
- - docker_insecure_registries | length > 0
- - name: Tag and push images to local registry. It might take a few minutes...
- shell: |
- export version_file={{ offline_data_path }}/versions.json
- if ! [ -f "$version_file" ]; then
- echo "[ERROR] version file $version_file is empty! "
- exit
- fi
- imgs=( $(cat $version_file |jq '.dockers |to_entries[] |.key +":"+ .value' | xargs) )
- echo imgs ${imgs[@]}
- export registry=$(cat $version_file | jq .registry |xargs)
- if [ -z "$registry" ]; then
- echo "[ERROR] registry is empty!"
- exit
- fi
- push_and_tag(){
- local img_name_version=$1
- docker tag registry.cn-beijing.aliyuncs.com/$registry/$img_name_version \
- $insecure_registry/$registry/$img_name_version && \
- docker push $insecure_registry/$registry/$img_name_version
- }
- export -f push_and_tag
- for i in {{docker_insecure_registries | join(" ")}}
- do
- docker load -i $i
- insecure_registry=$i parallel --jobs $(nproc) push_and_tag ::: "${imgs[@]}"
- done
- args:
- executable: /bin/bash
- become: yes
- when:
- - docker_insecure_registries is defined
- - docker_insecure_registries | length > 0
- - online_status == "offline"
- - offline_data_path is defined
- - offline_data_path | length > 0
- - name: Pull ocadm images on node
- command: "/opt/yunion/bin/ocadm config images pull --image-repository {{ image_repository | default('registry.cn-beijing.aliyuncs.com/yunion')}} --onecloud-version {{ onecloud_version | default('latest') }} --operator-version {{ onecloud_version | default('latest') }}"
- register: command_result
- changed_when: '"Image is up to date" not in command_result.stdout or "Already exists" not in command_result.stdout'
- retries: 3
- become: true
- delay: 10
- until: command_result.rc == 0
- when:
- - K8S_TOKEN.stdout|length == 0
- - online_status == "online"
- - name: Check node is init
- shell: test -f /etc/kubernetes/kubelet.conf
- register: kubelet_result
- ignore_errors: yes
- changed_when: false
- failed_when: false
- - block:
- - name: Construct controlplane endpoint
- set_fact:
- controlplane_endpoint: "{{k8s_controlplane_host}}:{{ k8s_controlplane_port | default(6443) }}"
- - name: Construct init args
- set_fact:
- init_args: "init --control-plane-endpoint {{ controlplane_endpoint }} --mysql-host {{ db_host }} --mysql-user {{ db_user }} --mysql-password {{ db_password}}"
- - name: Construct init args with db_port config
- set_fact:
- init_args: "{{ init_args }} --mysql-port {{ db_port }}"
- when:
- db_port is defined
- - name: Construct image repository
- set_fact:
- init_args: "{{ init_args }} --image-repository {{ image_repository }}"
- when:
- image_repository is defined
- - name: Construct init args apiserver_advertise_address
- set_fact:
- init_args: "{{ init_args }} --apiserver-advertise-address {{ apiserver_advertise_address }} "
- when:
- apiserver_advertise_address is defined
- - name: Construct init args node_ip
- set_fact:
- init_args: "{{ init_args }} --node-ip {{ node_ip }}"
- when:
- node_ip is defined
- - name: Set host_networks_options
- set_fact:
- host_networks_options: "{{ host_networks | join(' --host-networks ') }}"
- when:
- host_networks is defined
- - name: Construct init args host_networks
- set_fact:
- init_args: "{{ init_args }} --host-networks {{ host_networks_options }} "
- when:
- host_networks is defined
- - name: construct hugepage args {{onecloud_version}}
- set_fact:
- init_args: "{{ init_args }} --enable-hugepage"
- when:
- - enable_hugepage is defined
- - onecloud_version is defined
- - onecloud_version is version('v3.10', ">=")
- - name: Construct onecloud version
- set_fact:
- init_args: "{{ init_args }} --onecloud-version {{ onecloud_version }} --operator-version {{ onecloud_version }}"
- when:
- onecloud_version is defined
- - name: Construct pod-network-cidr
- set_fact:
- init_args: "{{ init_args }} --pod-network-cidr {{ pod_network_cidr }}"
- when:
- pod_network_cidr is defined
- - name: Construct service-cidr
- set_fact:
- init_args: "{{ init_args }} --service-cidr {{ service_cidr }}"
- when:
- service_cidr is defined
- - name: Construct service-dns-domain
- set_fact:
- init_args: "{{ init_args }} --service-dns-domain {{ service_dns_domain }}"
- when:
- service_dns_domain is defined
- - name: Construct onecloud version
- set_fact:
- init_args: "{{ init_args }} --addon-calico-ip-autodetection-method {{ ip_autodetection_method }}"
- when:
- ip_autodetection_method is defined
- - name: Init ha ip
- set_fact:
- init_args: "{{ init_args }} --high-availability-vip {{ high_availability_vip }}"
- when:
- high_availability_vip is defined
- - name: Init keepalived version tag
- set_fact:
- init_args: "{{ init_args }} --keepalived-version-tag {{ keepalived_version_tag }}"
- when:
- keepalived_version_tag is defined
- - name: Init node as onecloud host agent
- set_fact:
- init_args: "{{ init_args }} --enable-host-agent"
- when:
- - join_as_host | default(false)|bool == true
- - block:
- - name: Set cgroup driver to systemd in kubelet.service
- lineinfile:
- path: /usr/lib/systemd/system/kubelet.service
- regexp: '^ExecStart=/usr/bin/kubelet$'
- line: 'ExecStart=/usr/bin/kubelet --cgroup-driver=systemd'
- become: true
- - name: reload systemd
- ansible.builtin.systemd:
- name: kubelet
- state: restarted
- daemon_reload: true
- become: true
- when:
- is_openeuler_based | default(false) | bool == true
- - name: show init args
- debug:
- msg: "/opt/yunion/bin/ocadm {{ init_args }}"
- - name: Use ocadm init first master node
- shell: |
- /opt/yunion/bin/ocadm {{ init_args }}
- become: true
- when: kubelet_result.rc != 0
- args:
- executable: /bin/bash
- - name: "Wait 500 seconds for primary master to response: {{ controlplane_endpoint }}"
- wait_for:
- host: "{{ k8s_controlplane_host }}"
- port: "{{ k8s_controlplane_port | default(6443)}}"
- delay: 1
- timeout: 500
- run_once: yes
- - name: Export KUBECONFIG in master's ~/.bashrc
- lineinfile:
- dest: ~/.bashrc
- line: "export KUBECONFIG=/etc/kubernetes/admin.conf"
- state: present
- create: yes
- regexp: '^export KUBECONFIG=.*'
- when:
- - shell is undefined or shell == 'bash'
- - name: Source kubectl bash completion in master's ~/.bashrc
- lineinfile:
- dest: ~/.bashrc
- line: "source <(kubectl completion bash)"
- state: present
- create: yes
- regexp: '.*kubectl completion bash.*'
- when:
- - shell is undefined or shell == 'bash'
- - name: Include utils/k8s/kubelet/extra-args tasks
- include_role:
- name: utils/k8s/kubelet/extra-args
|