-
Notifications
You must be signed in to change notification settings - Fork 0
145 lines (125 loc) · 4.92 KB
/
k3s.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
name: k3s Outbound Connectivity Test
on:
workflow_dispatch:
jobs:
k3s-test:
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@int-sh
with:
egress-policy: audit
- name: Checkout repository
uses: actions/checkout@v3
- run: cat /etc/resolv.conf
- name: Install k3d
shell: bash
run: |
# Disable swap otherwise memory enforcement does not work
# See: https://kubernetes.slack.com/archives/CEKK1KTN2/p1600009955324200
sudo swapoff -a
sudo rm -f /swapfile
curl -Lo ./k3d https://github.com/k3d-io/k3d/releases/download/v5.7.4/k3d-$(uname)-amd64
chmod +x ./k3d
sudo mv k3d /usr/local/bin
- name: Create k3d cluster
shell: bash
run: |
cat > k3d.yaml <<EOF
apiVersion: k3d.io/v1alpha5
kind: Simple
agents: 0
image: "rancher/k3s:latest"
registries:
create:
name: "registry.local"
host: "0.0.0.0"
hostPort: "5000"
config: |
mirrors:
"mirror.gcr.io":
endpoint:
- "https://mirror.gcr.io"
options:
k3s:
extraArgs:
# Let consumers use their own ingress and leave the builtin LB unclaimed
- arg: --disable=traefik
nodeFilters:
- server:*
# Let consumers use their own metrics-server and leave the builtin unclaimed
- arg: --disable=metrics-server
nodeFilters:
- server:*
# This is needed in order to support projected volumes with service account tokens.
# See:
# https://kubernetes.slack.com/archives/CEKK1KTN2/p1600268272383600
# https://stackoverflow.com/questions/74603633/k3s-allow-unauthenticated-access-to-oidc-endpoints
- arg: --kube-apiserver-arg=anonymous-auth=true
nodeFilters:
- server:*
# This sets the issuer to what sigstore scaffolding expects.
# See also: https://github.com/k3d-io/k3d/issues/1187
- arg: --kube-apiserver-arg=service-account-issuer=https://kubernetes.default.svc
nodeFilters:
- server:*
- arg: --kubelet-arg=max-pods=110
nodeFilters:
- server:*
- agent:*
EOF
echo "Using k3d config file: "
cat k3d.yaml
#k3d cluster create mycluster --wait --verbose
k3d cluster create mycluster --config k3d.yaml --timeout 5m --verbose
# K3d sets this up for us in the node, but we're responsible for the host
sudo echo "127.0.0.1 registry.local" | sudo tee -a /etc/hosts
- name: Set start time output
id: start-time
run: echo "k3d-start-time=$(echo $(($(date +%s%N)/1000000)))" >> $GITHUB_OUTPUT
shell: bash
- name: Verify k3s installation
run: kubectl get nodes
- run: docker ps
- name: Deploy app to local k8s cluster
run: |
kubectl apply -f k8s/deployment.yml # Ensure your deployment YAML is in the k8s folder
kubectl rollout status deployment/nginx-deployment # Use the correct deployment name
- name: Deploy test pod
run: |
kubectl apply -f - <<EOF
apiVersion: v1
kind: Pod
metadata:
name: test-pod
spec:
containers:
- name: curl-container
image: curlimages/curl:7.85.0
command: ["sh", "-c", "sleep infinity"]
EOF
- name: Wait for pod to be ready
run: kubectl wait --for=condition=Ready pod/test-pod --timeout=60s
- name: Verify outbound connectivity
run: |
kubectl exec test-pod -- curl -I https://www.google.com
- name: Check pod logs
run: kubectl logs test-pod
- run: cat /etc/resolv.conf
- name: Get Kubernetes events
run: kubectl get events --all-namespaces
- name: Print k3s server logs
if: always()
run: |
docker logs k3d-mycluster-server-0
docker exec k3d-mycluster-server-0 cat /etc/resolv.conf
docker inspect k3d-mycluster-server-0 | grep -i networkmode
- name: Print k3s agent logs (if any)
if: ${{ inputs.worker-count != '0' }}
run: |
echo "==== k3s Agent Logs ===="
AGENT_CONTAINERS=$(docker ps --filter "name=k3d-${CLUSTER_NAME}-agent-" --format "{{.Names}}")
for AGENT_CONTAINER in $AGENT_CONTAINERS; do
echo "Agent container: $AGENT_CONTAINER"
docker logs $AGENT_CONTAINER
done