-
Notifications
You must be signed in to change notification settings - Fork 123
146 lines (127 loc) · 4.75 KB
/
eks.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
name: 'EKS'
on:
schedule:
# Runs "At 11:00 UTC every day-of-week"
- cron: '0 11 * * *'
workflow_dispatch:
inputs:
testName:
description: 'Test Run-Name'
required: true
default: 'EKS'
permissions:
contents: read
env:
AWS_REGION: ap-northeast-3
jobs:
terraform:
permissions: write-all
name: 'Terraform with eks'
runs-on: ubuntu-latest
environment: production
# Use the Bash shell regardless whether the GitHub Actions runner is ubuntu-latest, macos-latest, or windows-latest
defaults:
run:
shell: bash
working-directory: ./cicd/eks
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout
uses: actions/checkout@v3
# Run this only on main repo
- name: Check Repo owner
if: github.repository != 'loxilb-io/loxilb'
run: |
gh run cancel ${{ github.run_id }}
gh run watch ${{ github.run_id }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# AWS check
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
# Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc.
- name: Terraform Init
run: terraform init
# Generates an execution plan for Terraform
- name: Terraform Plan
run: terraform plan -input=false
- name: Terraform Apply
run: terraform apply -auto-approve -input=false
- name: Install and kubectl
run: |
VERSION=$(curl --silent https://storage.googleapis.com/kubernetes-release/release/stable.txt)
curl https://storage.googleapis.com/kubernetes-release/release/$VERSION/bin/linux/amd64/kubectl \
--progress-bar \
--location \
--remote-name
chmod +x kubectl
sudo mv kubectl /usr/local/bin/
- name: Get envs
run: |
echo "LOXILB_PUBLIC_IP=$(terraform output -raw loxilb_public_ip)" >> $GITHUB_ENV
echo "LOXILB_PRIVATE_IP=$(terraform output -raw loxilb_private_ip)" >> $GITHUB_ENV
echo "HOST_PUBLIC_IP=$(terraform output -raw host_public_ip)" >> $GITHUB_ENV
echo "HOST_PRIVATE_IP=$(terraform output -raw host_private_ip)" >> $GITHUB_ENV
echo "LOXILB_USER=ubuntu" >> $GITHUB_ENV
echo "HOST_USER=ubuntu" >> $GITHUB_ENV
- name: Loxilb update
uses: appleboy/[email protected]
with:
host: ${{ env.LOXILB_PUBLIC_IP }}
username: ${{ env.LOXILB_USER }}
key: ${{ secrets.AWS_SSH_KEY }}
port: 22
script_stop: true
script: |
sudo docker image pull ghcr.io/loxilb-io/loxilb:latest
sudo docker stop loxilb
sudo docker rm loxilb
sudo docker run -u root --cap-add SYS_ADMIN --net host --restart unless-stopped --privileged -dit -v /dev/log:/dev/log --name loxilb ghcr.io/loxilb-io/loxilb:latest
sleep 20
sudo docker exec loxilb /root/loxilb-io/loxilb/loxilb -v
- name: get kubeconfig
run: aws eks --region $(terraform output -raw region) update-kubeconfig --name $(terraform output -raw cluster_name)
- name: kube-loxilb apply
run: |
export LOXILB_PRIVATE_IP=${{ env.LOXILB_PRIVATE_IP }}
envsubst < kube-loxilb.yaml | kubectl apply -f -
sleep 60
- name: make Service with Pod
run: |
kubectl apply -f nginx-svc.yaml
sleep 10
kubectl apply -f udp-svc.yaml
sleep 10
kubectl apply -f sctp-svc.yaml
sleep 20
echo "**** svc info ****"
kubectl get svc
echo "**** pods info ****"
kubectl get pods -A
- name: Host Commands
uses: appleboy/[email protected]
with:
host: ${{ env.HOST_PUBLIC_IP }}
username: ${{ env.HOST_USER }}
key: ${{ secrets.AWS_SSH_KEY }}
port: 22
script: |
curl http://${{ env.LOXILB_PUBLIC_IP }}:8080
sleep 10
./udp_client ${{ env.LOXILB_PUBLIC_IP }} 50003
sleep 10
for i in $(seq 1 10); do ./sctp_client ${{ env.HOST_PRIVATE_IP }} 0 ${{ env.LOXILB_PUBLIC_IP }} 55004; sleep 1; done
- name: delete k8s configure
run: |
kubectl delete -f nginx-svc.yaml
kubectl delete -f udp-svc.yaml
kubectl delete -f sctp-svc.yaml
kubectl delete -f kube-loxilb.yaml
- name : delete testbed
if: ${{ ! cancelled() }}
run: |
terraform destroy -auto-approve -input=false