---
# Copyright kubeinit contributors
# All Rights Reserved.
#
# 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.
- name: Setup the cluster provision container
ansible.builtin.include_role:
name: kubeinit.kubeinit.kubeinit_services
tasks_from: create_provision_container.yml
vars:
kubeinit_deployment_node_name: "{{ kubeinit_provision_service_node }}"
kubeinit_deployment_pod_name: "{{ hostvars[kubeinit_provision_service_node].guest_name }}-pod"
kubeinit_deployment_delegate: "{{ hostvars[kubeinit_provision_service_node].target }}"
kubeinit_deployment_os: "{{ hostvars[kubeinit_provision_service_node].os }}"
- name: Configure the service node
block:
- name: Install common requirements
ansible.builtin.package:
name: "{{ kubeinit_eks_common_dependencies }}"
state: present
when: kubeinit_eks_common_dependencies is defined
- name: Remove repo before adding it
ansible.builtin.file:
path: /etc/yum.repos.d/kubernetes.repo
state: absent
- name: Creating a repository file for Kubernetes
ansible.builtin.file:
path: /etc/yum.repos.d/kubernetes.repo
state: touch
mode: '0644'
- name: Adding repository details in Kubernetes repo file.
ansible.builtin.blockinfile:
path: /etc/yum.repos.d/kubernetes.repo
block: |
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-$basearch
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
exclude=kubelet kubeadm kubectl
#
# Kubernetes config
#
- name: Fetch EKS kubernetes release
ansible.builtin.command: curl -s https://raw.githubusercontent.com/aws/eks-distro/main/release/DEFAULT_RELEASE_BRANCH
register: _result_release
changed_when: "_result_release.rc == 0"
- name: Set EKS kubernetes major-minor fact
ansible.builtin.set_fact:
kubeinit_eks_kubernetes_major_minor: "{{ _result_release.stdout | trim }}"
- name: Discover the revision number for eks
ansible.builtin.command: curl -s https://raw.githubusercontent.com/aws/eks-distro/main/release/{{ kubeinit_eks_kubernetes_major_minor }}/production/RELEASE
register: _result_revision
changed_when: "_result_revision.rc == 0"
- name: Set EKS release number fact
ansible.builtin.set_fact:
kubeinit_eks_revision: "{{ _result_revision.stdout | trim }}"
- name: Discover the git tag for eks
ansible.builtin.command: curl -s https://raw.githubusercontent.com/aws/eks-distro/main/projects/kubernetes/release/{{ kubeinit_eks_kubernetes_major_minor }}/GIT_TAG
register: _result_gittag
changed_when: "_result_gittag.rc == 0"
- name: Set EKS string facts
ansible.builtin.set_fact:
kubeinit_eks_kubernetes_dirname: "kubernetes-{{ kubeinit_eks_kubernetes_major_minor }}"
kubeinit_eks_kubernetes_filename: "kubernetes-{{ kubeinit_eks_kubernetes_major_minor + '-eks-' + kubeinit_eks_revision }}.yaml"
kubeinit_eks_kubernetes_gittag: "{{ (_result_gittag.stdout | trim) + '-eks-' + kubeinit_eks_kubernetes_major_minor + '-' + kubeinit_eks_revision }}"
- name: Set complete EKS kubernetes version
ansible.builtin.set_fact:
kubeinit_eks_kubernetes_version: "{{ kubeinit_eks_kubernetes_major_minor.replace('-','.') }}"
- name: Install YQ
ansible.builtin.shell: |
set -eo pipefail
python3 -m pip install yq
args:
executable: /bin/bash
register: _result
changed_when: "_result.rc == 0"
- name: Discover full version of Kubernetes that will be deployed
ansible.builtin.shell: |
set -o pipefail
set -e
curl -s https://distro.eks.amazonaws.com/kubernetes-{{ kubeinit_eks_kubernetes_major_minor }}/kubernetes-{{ kubeinit_eks_kubernetes_major_minor }}-eks-{{ kubeinit_eks_revision }}.yaml | \
yq '.status.components | map(select(.name == "kubernetes")) | .[0].gitTag' | tr -d '"' | tr -d 'v'
args:
executable: /bin/bash
register: _result_kubernetes_version_full
changed_when: "_result_kubernetes_version_full.rc == 0"
- name: Set EKS release number fact
ansible.builtin.set_fact:
kubeinit_eks_kubernetes_version_full: "{{ _result_kubernetes_version_full.stdout | trim }}"
- name: Install requirements
ansible.builtin.command: dnf install -y kubectl-{{ kubeinit_eks_kubernetes_version_full }} --disableexcludes=kubernetes
register: _result
changed_when: "_result.rc == 0"
- name: Install (replace) requirements
ansible.builtin.shell: |
set -eo pipefail
kubectl_bin=$( curl -s https://distro.eks.amazonaws.com/kubernetes-{{ kubeinit_eks_kubernetes_major_minor }}/kubernetes-{{ kubeinit_eks_kubernetes_major_minor }}-eks-{{ kubeinit_eks_revision }}.yaml | \
yq '.status.components | map(select(.name == "kubernetes")) | .[0].assets | map(select(.name == "bin/linux/amd64/kubectl")) | .[0].archive.uri' | tr -d '"')
wget -q $kubectl_bin
chmod +x kubectl
mv ./kubectl $(which kubectl)
args:
executable: /bin/bash
register: _result
changed_when: "_result.rc == 0"
- name: Install services requirements
ansible.builtin.package:
name: skopeo
state: present
#
# Configure local registry
#
- name: Get the required container images
ansible.builtin.shell: |
set -eo pipefail
curl -s https://distro.eks.amazonaws.com/{{ kubeinit_eks_kubernetes_dirname }}/{{ kubeinit_eks_kubernetes_filename }} | \
sed -n -e "s|^.*uri: \(public.ecr.aws/eks-distro\)|\1|p" > ~/kubeinit_deployment_images.txt
echo public.ecr.aws/eks-distro/kubernetes/kube-proxy-base:{{ kubeinit_eks_kubernetes_gittag }} >> ~/kubeinit_deployment_images.txt
echo public.ecr.aws/eks-distro/kubernetes/go-runner:{{ kubeinit_eks_kubernetes_gittag }} >> ~/kubeinit_deployment_images.txt
args:
executable: /bin/bash
register: _result
changed_when: "_result.rc == 0"
- name: Mirror EKS remote registry to local
ansible.builtin.shell: |
set -o pipefail
set -e
mkdir -p /etc/containers/
cat << EOF > /etc/containers/policy.json
{
"default": [
{
"type": "insecureAcceptAnything"
}
],
"transports":
{
"docker-daemon":
{
"": [{"type":"insecureAcceptAnything"}]
}
}
}
EOF
echo "function skopeo_copy {" > skopeo_copy.bash
echo " skopeo copy docker://\$1 docker://{{ kubeinit_registry_uri }}/\$2 --dest-creds {{ kubeinit_registry_user }}:{{ kubeinit_registry_password }}" >> ~/skopeo_copy.bash
echo "}" >> ~/skopeo_copy.bash
sed -e 's;^\(public.ecr.aws/\)\(.*/\)\(.*\);skopeo_copy "\1\2\3" "\2\3"\nskopeo_copy "\1\2\3" "\3";' ~/kubeinit_deployment_images.txt >> ~/skopeo_copy.bash
bash ~/skopeo_copy.bash
args:
executable: /bin/bash
register: _result
changed_when: "_result.rc == 0"
when: "'registry' in kubeinit_cluster_hostvars.services"
delegate_to: "{{ kubeinit_provision_service_node }}"