diff --git a/providers/amazon/images/ivy-kubernetes/provision.yml b/providers/amazon/images/ivy-kubernetes/provision.yml new file mode 100644 index 0000000..52e11ab --- /dev/null +++ b/providers/amazon/images/ivy-kubernetes/provision.yml @@ -0,0 +1,8 @@ +--- +- name: Provision a machine + hosts: 127.0.0.1 + user: ec2-user + connection: local + roles: + - kubernetes + - vault diff --git a/roles/kubernetes/defaults/main.yml b/roles/kubernetes/defaults/main.yml new file mode 100644 index 0000000..aec8d7c --- /dev/null +++ b/roles/kubernetes/defaults/main.yml @@ -0,0 +1,39 @@ +--- +# Versions +etcd_version: "v3.4.9" +cfssl_version: "1.4.1" +kubernetes_version: "v1.18.5" +containerd_version: "1.3.4" +cni_plugins_version: "v0.8.6" +# Download dirs +tmp_dir: "/tmp" +bin_dir: "/usr/local/bin" +# ETCD +etcd_url: "https://github.com/etcd-io/etcd/releases/download/{{ etcd_version }}/etcd-{{ etcd_version }}-linux-amd64.tar.gz" +etcd_dest: "{{ tmp_dir }}/etcd-{{ etcd_version }}-linux-amd64.tar.gz" +# cfssl +cfssl_url: "https://github.com/cloudflare/cfssl/releases/download/v{{ cfssl_version }}/cfssl_{{ cfssl_version }}_linux_amd64" +cfssl_dest: "{{ bin_dir }}/cfssl" +cfssljson_url: "https://github.com/cloudflare/cfssl/releases/download/v{{ cfssl_version }}/cfssljson_{{ cfssl_version }}_linux_amd64" +cfssljson_dest: "{{ bin_dir }}/cfssljson" +# Kubernetes URL +kubernetes_base_url: "https://storage.googleapis.com/kubernetes-release/release" +# kubernetes master +kubernetes_api_url: "{{ kubernetes_base_url }}/{{ kubernetes_version }}/bin/linux/amd64/kube-apiserver" +kubernetes_api_dest: "{{ bin_dir }}/kube-apiserver" +kubernetes_controller_manager_url: "{{ kubernetes_base_url }}/{{ kubernetes_version }}/bin/linux/amd64/kube-controller-manager" +kubernetes_controller_manager_dest: "{{ bin_dir }}/kube-controller-manager" +kubernetes_scheduler_url: "{{ kubernetes_base_url }}/{{ kubernetes_version }}/bin/linux/amd64/kube-scheduler" +kubernetes_scheduler_dest: "{{ bin_dir }}/kube-scheduler" +# kubernetes worker +kubernetes_proxy_url: "{{ kubernetes_base_url }}/{{ kubernetes_version }}/bin/linux/amd64/kube-proxy" +kubernetes_proxy_dest: "{{ bin_dir }}/kube-proxy" +kubelet_url: "{{ kubernetes_base_url }}/{{ kubernetes_version }}/bin/linux/amd64/kubelet" +kubelet_dest: "{{ bin_dir }}/kubelet" +# all kubernetes hosts +kubectl_url: "{{ kubernetes_base_url }}/{{ kubernetes_version }}/bin/linux/amd64/kubectl" +kubectl_dest: "{{ bin_dir }}/kubectl" +containerd_url: "https://storage.googleapis.com/cri-containerd-release/cri-containerd-{{ containerd_version }}.linux-amd64.tar.gz" +containerd_dest: "{{ tmp_dir }}/cri-containerd-{{ containerd_version }}.linux-amd64.tar.gz" +cni_plugins_url: "https://github.com/containernetworking/plugins/releases/download/{{ cni_plugins_version }}/cni-plugins-linux-amd64-{{ cni_plugins_version }}.tgz" +cni_plugins_dest: "{{ tmp_dir }}/cni-plugins-linux-amd64-{{ cni_plugins_version }}.tgz" diff --git a/roles/kubernetes/files/etc/etcd/etcdctl.env b/roles/kubernetes/files/etc/etcd/etcdctl.env new file mode 100644 index 0000000..081f910 --- /dev/null +++ b/roles/kubernetes/files/etc/etcd/etcdctl.env @@ -0,0 +1,7 @@ +export ETCDCTL_API=3 + +export ETCDCTL_CACERT=/etc/etcd/pki/ca.crt +export ETCDCTL_CERT=/etc/etcd/pki/etcdctl-etcd-client.crt +export ETCDCTL_KEY=/etc/etcd/pki/etcdctl-etcd-client.key + +export ETCDCTL_DIAL_TIMEOUT=3s diff --git a/roles/kubernetes/files/etc/systemd/system/sys-fs-bpf.mount b/roles/kubernetes/files/etc/systemd/system/sys-fs-bpf.mount new file mode 100644 index 0000000..4f84f01 --- /dev/null +++ b/roles/kubernetes/files/etc/systemd/system/sys-fs-bpf.mount @@ -0,0 +1,15 @@ +[Unit] +Description=Cilium BPF mounts +Documentation=https://docs.cilium.io/ +DefaultDependencies=no +Before=local-fs.target umount.target +After=swap.target + +[Mount] +What=bpffs +Where=/sys/fs/bpf +Type=bpf +Options=rw,nosuid,nodev,noexec,relatime,mode=700 + +[Install] +WantedBy=multi-user.target diff --git a/roles/kubernetes/files/opt/ivy/kubernetes/generate-admin-config.sh b/roles/kubernetes/files/opt/ivy/kubernetes/generate-admin-config.sh new file mode 100755 index 0000000..e981bb5 --- /dev/null +++ b/roles/kubernetes/files/opt/ivy/kubernetes/generate-admin-config.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +set -euo pipefail +IFS=$'\n\t' + +CLUSTER_NAME="${1:-ivynetes}" +CERTIFICATE_AUTHORITY_LOCATION="${2:-/var/lib/kubernetes/ca.pem}" +EMBED_CERTS="${3:-true}" +API_SERVER_ENDPOINT="${4:-https://127.0.0.1:6443}" +ADMIN_CERTIFICATE_LOCATION="${5:-/var/lib/kubernetes/admin.pem}" +ADMIN_KEY_LOCATION="${6:-/var/lib/kubernetes/admin-key.pem}" + +kubectl config set-cluster "${CLUSTER_NAME}" \ + --certificate-authority="${CERTIFICATE_AUTHORITY_LOCATION}" \ + --embed-certs="${EMBED_CERTS}" \ + --server="${API_SERVER_ENDPOINT}" \ + --kubeconfig=admin.kubeconfig + +kubectl config set-credentials admin \ + --client-certificate="${ADMIN_CERTIFICATE_LOCATION}" \ + --client-key="${ADMIN_KEY_LOCATION}" \ + --embed-certs="${EMBED_CERTS}" \ + --kubeconfig=admin.kubeconfig + +kubectl config set-context default \ + --cluster="${CLUSTER_NAME}" \ + --user=admin \ + --kubeconfig=admin.kubeconfig + +kubectl config use-context default --kubeconfig=admin.kubeconfig diff --git a/roles/kubernetes/files/opt/ivy/kubernetes/generate-encryption-config.sh b/roles/kubernetes/files/opt/ivy/kubernetes/generate-encryption-config.sh new file mode 100755 index 0000000..b4d12bc --- /dev/null +++ b/roles/kubernetes/files/opt/ivy/kubernetes/generate-encryption-config.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +set -euo pipefail +IFS=$'\n\t' + +ENCRYPTION_KEY=$(head -c 32 /dev/urandom | base64) +ENCRYPTION_LOCATION="${1:-encryption-config.yaml}" + +cat > "${ENCRYPTION_LOCATION}" <&2 + return 1 + ;; + esac + local CA_CRT="${CA_TRUST_DIR}/ivy.pem" + get_ssm_param "${SSM_CA_CERTIFICATE}" "${REGION}" > "${CA_CRT}" + sudo ${UPDATE_CA_COMMAND} +}