Equinix k8s Action #35
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Equinix k8s Action | |
on: | |
workflow_dispatch: | |
inputs: | |
termination_time: | |
description: 'Cluster termination time in hours after now' | |
required: true | |
default: '1' | |
control_plan: | |
description: 'control plane machine type' | |
required: false | |
default: 'c3.small.x86' | |
node_plan: | |
description: 'node machine type' | |
required: false | |
default: 'c3.small.x86' | |
metro: | |
description: 'metro location' | |
required: false | |
default: 'da' | |
jobs: | |
Create-k8s-cluster: | |
name: "Create Cluster" | |
runs-on: ubuntu-latest | |
steps: | |
- name: Validate termination time | |
run: | | |
if [ ${{ github.event.inputs.termination_time }} -gt 48 ]; then | |
echo "Error: Termination time cannot be more than 48 hours." | |
exit 1 | |
fi | |
- name: Install ansible, git and jq | |
run: | | |
sudo apt-get update | |
sudo apt-get install ansible jq git -y | |
- name: Clone repo | |
run: | | |
git clone https://github.com/sustainable-computing-io/kepler-metal-ci | |
- name: Save ssh key from env to file | |
run: | | |
mkdir -p ~/.ssh/ | |
echo "${{ secrets.EQUINIX_SSH_KEY }}" > ~/.ssh/kepler_ci | |
chmod 600 ~/.ssh/kepler_ci | |
echo "StrictHostKeyChecking no" >> ~/.ssh/config | |
- name: Create metal config | |
run: | | |
cat <<EOF > /tmp/metal.yaml | |
token: "${{ secrets.METAL_AUTH_TOKEN }}" | |
project-id: ${{ secrets.EQUINIX_PROJECT_ID }} | |
EOF | |
- name: Play k8s_kubeadm.yml | |
env: | |
metro: "da" | |
plan: "c3.small.x86" | |
os: "rhel_9" | |
run: | | |
mkdir -p ~/.ansible | |
echo '[defaults]' > ~/.ansible/ansible.cfg | |
echo 'callback_plugins = ~/.github/callback_plugins' >> ~/.ansible/ansible.cfg | |
echo 'callback_whitelist = mask_ip_callback' >> ~/.ansible/ansible.cfg | |
mkdir -p ~/.github/callback_plugins | |
cd kepler-metal-ci | |
cp ansible/mask_ip_callback.py ~/.github/callback_plugins/mask_ip_callback.py | |
# save input var into extra-vars.yaml | |
echo "termination_time: ${{ github.event.inputs.termination_time }}" > /tmp/extra-vars.yaml | |
echo "control_plan: ${{ github.event.inputs.control_plan }}" >> /tmp/extra-vars.yaml | |
echo "node_plan: ${{ github.event.inputs.node_plan }}" >> /tmp/extra-vars.yaml | |
echo "metro: ${{ github.event.inputs.metro }}" >> /tmp/extra-vars.yaml | |
ansible-playbook ansible/k8s_kubeadm.yml \ | |
--extra-vars "@/tmp/extra-vars.yaml" >> k8s_kubeadm.log | |
sudo cat /tmp/kubeconfig |jq -r '.stdout' > /tmp/k8sconfig | |
sudo mv /tmp/k8sconfig /tmp/kubeconfig | |
- name: Upload kubeconfig | |
uses: actions/upload-artifact@v2 | |
with: | |
name: kubeconfig-${{ github.run_id }} | |
path: /tmp/kubeconfig | |
retention-days: 1 | |
Test-K8s: | |
name: "Test K8s" | |
needs: create-k8s-cluster | |
runs-on: ubuntu-latest | |
steps: | |
- name: Install kubectl | |
run: | | |
curl -LO "https://dl.k8s.io/release/v1.22.0/bin/linux/amd64/kubectl" | |
chmod +x kubectl | |
sudo mv kubectl /usr/local/bin/ | |
- name: mkdir ~/.kube | |
run: | | |
mkdir -p ~/.kube | |
- name: Download kubeconfig | |
uses: actions/download-artifact@v2 | |
with: | |
name: kubeconfig-${{ github.run_id }} | |
path: ~/.kube/ | |
- name: Test k8s | |
run: | | |
ls -la ~/.kube/* | |
mv ~/.kube/kubeconfig ~/.kube/config | |
kubectl get nodes | |
kubectl get pods --all-namespaces | |
- name: Label workers | |
run: | | |
kubectl label node $(kubectl get nodes --selector=node-role.kubernetes.io/control-plane!= --no-headers -o custom-columns=":metadata.name") node-role.kubernetes.io/worker= | |
- name: Install Prometheus | |
run: | | |
git clone --depth 1 https://github.com/prometheus-operator/kube-prometheus; cd kube-prometheus; | |
kubectl apply --server-side --validate=false -f manifests/setup | |
until kubectl get servicemonitors --all-namespaces ; do date; sleep 1; echo ""; done | |
kubectl apply --validate=false -f manifests/ | |
kubectl wait deployments -n monitoring prometheus-adapter --for=condition=available --timeout 3m | |
kubectl rollout status --watch --timeout=600s statefulset -n monitoring prometheus-k8s | |
- name: Pull kube-burner | |
run: | | |
git clone https://github.com/kube-burner/kube-burner | |
curl -sS -L "https://github.com/kube-burner/kube-burner/releases/download/v1.9.5/kube-burner-V1.9.5-linux-x86_64.tar.gz" | tar -xzC kube-burner/ kube-burner | |
- name: Port forward prom | |
run: | | |
kubectl port-forward -n monitoring svc/prometheus-k8s 9090:9090 & | |
- name: Run kube-burner node-density | |
run: | | |
cp kube-burner/examples/metrics-profiles/metrics.yaml kube-burner/examples/workloads/kubelet-density/metrics.yaml | |
cd kube-burner/examples/workloads/kubelet-density | |
sed -i 's/qps: 2/qps: 20/g' kubelet-density.yml | |
sed -i 's/burst: 2/burst: 20/g' kubelet-density.yml | |
sed -i 's/jobIterations: 25/jobIterations: 80/g' kubelet-density.yml | |
echo "indexers:" >> kubelet-density.yml | |
echo " - type: local" >> kubelet-density.yml | |
echo " metricsDirectory: collected-metrics" >> kubelet-density.yml | |
../../../kube-burner init -c kubelet-density.yml -u http://localhost:9090 --metrics-profile metrics.yaml |