Skip to content

Commit

Permalink
Merge pull request #302 from redhat-nfvpe/dev/remove_artifacts
Browse files Browse the repository at this point in the history
Remove artifacts due to no longer maintainanced and put rpm install
  • Loading branch information
dougbtv authored Dec 2, 2019
2 parents 610f0bd + fb3f81b commit d4a5b86
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 105 deletions.
48 changes: 0 additions & 48 deletions docs/building_k8s.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,51 +79,3 @@ executed to build the release.

The resulting release binaries will be on the builder virtual machine in
`/home/centos/src/go/src/k8s.io/kubernetes/bazel-bin/build/`.

## Copying Artifacts to Kubernetes Nodes

When you run the `builder.yml`, at the end of the build, the artifacts will be
copied over to your Kubernetes nodes (assuming you're consuming the
automatically built inventory file `vms.local.generated`, otherwise you need to
specify your own inventory file that contains the `master` and `nodes` groups
of your Kubernetes nodes).

Artifacts are copied onto the Kubernetes nodes and placed in the
`/opt/k8s/artifacts/` directory (optionally configurable via
`artifacts_sync_path`).

> **TIP**
>
> If you need to resync artifacts over to the virtual machines (for example, if
> you tore down your Kubernetes cluster, reinstantiated, but didn't destroy the
> builder VM with the artifacts) you can avoid rebuilding the entire set of
> artifacts and synchronize them back over using the `sync_artifacts` Ansible
> tag.
>
> `ansible-playbook -i inventory/vms.local.generated --tags sync_artifacts playbooks/ka-builder/builder.yml`
## Instantiating a Kubnernetes Cluster from Built Artifacts

Once you've completed the building of artifacts on the builder machine, you can
start up a Kubernetes cluster from those artifacts. All you need to do is pass
the `artifacts_install` variable to the `kube-install.yml` playbook, and the
artifacts that were previously synchronized over to the virtual machines will
be loaded and installed, then used by `kubeadm` during cluster spin up.

> **NOTE**
>
> You can only instantiate a Kubernetes cluster from version 1.10 (currently
> master) or later. Changes were made to Kubernetes to avoid the use of CGO
> when building the artifacts, which allows them to be consumed. In Kubernetes
> version 1.9 or earlier, these changes didn't exist, and would result in
> `kubeadm` crashing whenever it tried to initialize the cluster.
Instantiate the cluster using the artifacts with the following command:

```
ansible-playbook -i inventory/vms.local.generated -e "artifacts_install=true" playbooks/kube-install.yml
```

**PRO TIP**: You can also change the repository location and branch that the
builder uses, resulting in an ability to create a cluster with your own custom
changes to Kubernetes.
1 change: 0 additions & 1 deletion roles/kube-init/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
kubectl_user: centos
kubectl_group: centos
kubectl_home: /home/centos
artifacts_install: false
control_plane_listen_all: false
7 changes: 1 addition & 6 deletions roles/kube-init/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

- name: check kubeadm version (minor)
shell: >
kubeadm version -o json | jq -r .clientVersion.minor
kubeadm version -o json | jq -r .clientVersion.minor | sed -e 's/\+//g'
register: kubeadm_version_minor

- name: create kubeadm config file (<= 1.12)
Expand Down Expand Up @@ -57,11 +57,6 @@
set_fact:
k8s_version: ""

- name: Set custom Kubernetes version when installing via artifacts
set_fact:
k8s_version: "--kubernetes-version {{ kube_version }}"
when: artifacts_install

# Was trying to use flannel and running with:
# kubeadm init > /etc/kubeadm.init.txt
# abandonded for now...
Expand Down
6 changes: 6 additions & 0 deletions roles/kube-init/templates/kubeadm.cfg.v1beta2.j2
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ scheduler:
featureGates:
DevicePlugins: true
{% endif %}
{% if k8s_image_repository|default("") != "" %}
imageRepository: {{ k8s_image_repository }}
{% endif %}
{% if kube_version != "latest" %}
kubernetesVersion: {{ kube_version }}
{% endif %}
---
kind: InitConfiguration
apiVersion: kubeadm.k8s.io/v1beta2
Expand Down
1 change: 0 additions & 1 deletion roles/kube-install/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
binary_install: false
artifacts_install: false
artifacts_sync_path: /opt/k8s/artifacts
kubectl_home: /home/centos
skip_reboot: true
74 changes: 25 additions & 49 deletions roles/kube-install/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
template:
src: kubernetes.repo.j2
dest: /etc/yum.repos.d/kubernetes.repo
when: not artifacts_install

- name: Default kube version fact
set_fact:
Expand All @@ -17,24 +16,32 @@
- name: Set kube version fact to specific version when specified
set_fact:
kube_version_parameter: "-{{ kube_version }}"
when: kube_version != "latest" and not artifacts_install
when: kube_version != "latest"

- name: Get Kubernetes version when doing an artifacts-based installation
- name: copy/install Kubernetes packages
block:
- name: get contents
command: tar xfO {{ artifacts_sync_path }}/kube-proxy.tar manifest.json
register: raw_manifest
tags:
- skip_ansible_lint # needs to use tar to unpack and return file contents

- name: Set contents of raw manifest.json from kube-proxy container archive
set_fact:
manifest: "{{ raw_manifest.stdout|from_json }}"

- name: Get version of kube-proxy container archive from manifest variable
set_fact:
kube_version: "{{ manifest.0.RepoTags.0.split(':')[1] | replace('_', '+') }}"
when: artifacts_install
- name: copy rpm file
copy:
src: "{{ item }}"
dest: /root
owner: root
group: root
mode: "u=rw,g=r,o=r"
with_items:
- "{{ k8s_use_rpms }}/kubectl.rpm"
- "{{ k8s_use_rpms }}/kubelet.rpm"
- "{{ k8s_use_rpms }}/kubeadm.rpm"
- "{{ k8s_use_rpms }}/kubernetes-cni.rpm"
- name: Install required packages for Kubernetes deployment
package:
name: "{{ item }}"
state: present
with_items:
- "/root/kubectl.rpm"
- "/root/kubelet.rpm"
- "/root/kubeadm.rpm"
- "/root/kubernetes-cni.rpm"
when: k8s_use_rpms|default("") != ""

- name: Install required packages for Kubernetes deployment
package:
Expand All @@ -45,38 +52,7 @@
- kubelet{{ kube_version_parameter }}
- kubeadm{{ kube_version_parameter }}
- kubernetes-cni
when: not artifacts_install


# TODO: only install when packages are not already installed
- name: Install required packages from artifacts for Kubernetes deployment
block:
- name: Install RPMs for Kubernetes from artifacts
yum:
name: "{{ item }}"
state: present
with_items:
- "{{ artifacts_sync_path }}/kubeadm-x86_64.rpm"
- "{{ artifacts_sync_path }}/kubectl-x86_64.rpm"
- "{{ artifacts_sync_path }}/kubelet-x86_64.rpm"
- "{{ artifacts_sync_path }}/kubernetes-cni-x86_64.rpm"

- name: Get list of container image archives
find:
paths: "{{ artifacts_sync_path }}"
patterns: "*.tar"
register: container_image_archives

- name: Load container images
command: |
docker load -i {{ item.path }}
with_items: "{{ container_image_archives.files }}"

- name: Retag the container images
shell: >
docker images --format "docker tag {{'{{'}}.Repository{{'}}'}}:{{'{{'}}.Tag{{'}}'}} {{'{{'}}.Repository{{'}}'}}-amd64:{{'{{'}}.Tag{{'}}'}}" | sh
when: artifacts_install
when: k8s_use_rpms|default("") == ""

- name: Optionally include playbook for binary install
include: binary_install.yml
Expand Down

0 comments on commit d4a5b86

Please sign in to comment.