forked from kubernetes-sigs/kind
-
Notifications
You must be signed in to change notification settings - Fork 0
188 lines (171 loc) · 5.76 KB
/
metallb.yml
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
name: LoadBalancer-MetalLB
on:
workflow_dispatch:
push:
pull_request:
branches:
- main
paths-ignore:
- 'site/**'
permissions:
contents: read
jobs:
LoadBalancer-MetalLB:
name: LoadBalancer-MetalLB
runs-on: ubuntu-20.04
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
ipFamily: [ipv4]
deployment: [singleNode, multiNode]
env:
JOB_NAME: "docker-${{ matrix.deployment }}-${{ matrix.ipFamily }}"
IP_FAMILY: ${{ matrix.ipFamily }}
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- name: Install kind
run: sudo make install INSTALL_DIR=/usr/local/bin
- name: Install kubectl
run: |
curl -LO https://dl.k8s.io/release/$(curl -sL https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
- name: Enable ipv4 and ipv6 forwarding
run: |
sudo sysctl -w net.ipv6.conf.all.forwarding=1
sudo sysctl -w net.ipv4.ip_forward=1
- name: Create single node cluster
if: ${{ matrix.deployment == 'singleNode' }}
run: |
cat <<EOF | /usr/local/bin/kind create cluster -v7 --wait 1m --retain --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
networking:
ipFamily: ${IP_FAMILY}
EOF
- name: Create multi node cluster
if: ${{ matrix.deployment == 'multiNode' }}
run: |
cat <<EOF | /usr/local/bin/kind create cluster -v7 --wait 1m --retain --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
networking:
ipFamily: ${IP_FAMILY}
nodes:
- role: control-plane
- role: worker
- role: worker
EOF
- name: Get Cluster status
run: |
# wait network is ready
kubectl wait --for=condition=ready pods --namespace=kube-system -l k8s-app=kube-dns
kubectl get nodes -o wide
kubectl get pods -A
ping -c 5 172.18.0.2
- name: Install Helm
run: |
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh
# - name: Install and configure MetalLB
# run: |
# helm repo add metallb https://metallb.github.io/metallb
# helm install metallb metallb/metallb --namespace metallb-system --create-namespace
# kubectl wait --for=condition=Ready pods --all -n metallb-system
# kubectl get pods -A
# docker network inspect -f '{{.IPAM.Config}}' kind
# cat <<EOF | kubectl apply -f -
# apiVersion: metallb.io/v1beta1
# kind: IPAddressPool
# metadata:
# name: first-pool
# namespace: metallb-system
# spec:
# addresses:
# - 172.18.200.0/24
# avoidBuggyIPs: true
# ---
# apiVersion: metallb.io/v1beta1
# kind: L2Advertisement
# metadata:
# name: empty
# namespace: metallb-system
# EOF
- name: Check Network
run: |
ip a
ip route
- name: Deploy nginx
run: |
kubectl create deployment nginx --image=nginx --replicas=3
kubectl wait pod --all --for=condition=Ready -n default
kubectl expose deployment nginx --name=nginx --type=LoadBalancer --port=80
kubectl get pods
kubectl get services
kubectl describe services nginx
kubectl get services | grep nginx | awk '{ print $4 }'
curl -m 5 http://$(kubectl get services | grep nginx | awk '{ print $4 }'):80
- name: Test LoadBalancer
run: |
cat <<EOF | kubectl apply -f -
kind: Pod
apiVersion: v1
metadata:
name: foo-app
labels:
app: http-echo
spec:
containers:
- name: foo-app
image: hashicorp/http-echo:0.2.3
args:
- "-text=foo"
---
kind: Pod
apiVersion: v1
metadata:
name: bar-app
labels:
app: http-echo
spec:
containers:
- name: bar-app
image: hashicorp/http-echo:0.2.3
args:
- "-text=bar"
---
kind: Service
apiVersion: v1
metadata:
name: foo-service
spec:
type: LoadBalancer
selector:
app: http-echo
ports:
# Default port used by the image
- port: 5678
EOF
kubectl wait pod --all --for=condition=Ready -n default
kubectl get services
timeout 20s bash -c 'until kubectl get service/foo-service --output=jsonpath='{.status.loadBalancer}' | grep "ingress"; do : ; done'
kubectl get services
LB_IP=$(kubectl get svc/foo-service -o=jsonpath='{.status.loadBalancer.ingress[0].ip}')
curl -m 5 http://${LB_IP}:5678
- name: Export logs
if: always()
run: |
mkdir -p /tmp/kind/logs
/usr/local/bin/kind export logs /tmp/kind/logs
sudo chown -R $USER:$USER /tmp/kind/logs
- name: Upload logs
if: always()
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
with:
name: kind-logs-${{ env.JOB_NAME }}-${{ github.run_id }}
path: /tmp/kind/logs
- name: Delete cluster
run: /usr/local/bin/kind delete cluster