-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_k8s_frpc.sh
146 lines (118 loc) · 3.26 KB
/
install_k8s_frpc.sh
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
#!/bin/bash -e
if [ -n "$(echo $REPO | grep ^http)" ]
then
source <(curl -Ls ${REPO}/env_function.sh)
else
source ${REPO}/env_function.sh
fi
FRPC_TOML=frpc.toml
FRPC_YAML=${name}.yaml
bind_ips=$(getarg bind_ips $@)
bind_port=$(getarg bind_port $@)
bind_port=${bind_port:-7000}
tmpdir=$(getarg tmpdir $@)
tmpdir=${tmpdir:-"$(pwd)"}
tmpdir=${tmpdir}/.k8s_${name}
namespace=$(getarg namespace $@)
namespace=${namespace:-higress-system}
http_upstream_host=$(getarg http_upstream_host $@)
http_upstream_host=${http_upstream_host:-higress-gateway.higress-system.svc.cluster.local}
http_upstream_port=$(getarg http_upstream $@)
http_upstream_port=${http_upstream:-80}
http_route_rule=$(getarg http_route_rule $@)
http_route_rule=${http_route_rule:-"*"}
tcp_upstream_host=$(getarg tcp_upstream_host $@)
tcp_upstream_host=${tcp_upstream_host:-local}
tcp_upstream_port=$(getarg tcp_upstream $@)
tcp_upstream_port=${tcp_upstream:-8080}
tcp_route_rule=$(getarg tcp_route_rule $@)
tcp_route_rule=${tcp_route_rule:-"tcp-*"}
token=$(getarg token $@)
token=${token:-Pa44VV0rd14VVrOng}
if [ ! -n "$bind_ips" ]; then
echo "missing bind_ips"
exit 0
fi
install_frpc(){
mkdir -p $tmpdir
name=$(getarg name $@)
name=${name:-frpc}
bind_ip=$(getarg bind_ip $@)
cat << EOF > ${tmpdir}/frpc.toml
serverAddr = "${bind_ip}"
serverPort = ${bind_port}
auth.token = "${token}"
log.level = "debug"
[[proxies]]
name = "k8s-tcp-${name}"
type = "tcpmux"
multiplexer = "httpconnect"
localIp = "${tcp_upstream_host}"
localPort = ${tcp_upstream_port}
customDomains = ["${tcp_route_rule}"]
EOF
local _idx=0
http_route_rule=$(echo $http_route_rule | tr ',' ' ')
for domain in $http_route_rule
do
local _idx=`expr $_idx + 1`
cat << EOF >> ${tmpdir}/frpc.toml
[[proxies]]
name = "k8s-http-client${name}-domain${_idx}"
type = "http"
localIp = "${http_upstream_host}"
localPort = ${http_upstream_port}
customDomains = ["${domain}"]
EOF
done
echo "------------------------------------------------------"
cat ${tmpdir}/frpc.toml
echo "------------------------------------------------------"
kubectl delete secret ${name}.toml -n ${namespace} 2>/dev/null
kubectl create secret generic ${name}.toml -n ${namespace} --from-file=${tmpdir}/frpc.toml
cat << EOF > ${tmpdir}/${FRPC_YAML}
apiVersion: apps/v1
kind: Deployment
metadata:
name: ${name}
namespace: ${namespace}
labels:
app: ${name}
frps: ${bind_ip}
spec:
replicas: 1
selector:
matchLabels:
app: ${name}
template:
metadata:
labels:
app: ${name}
frps: ${bind_ip}
spec:
containers:
- name: ${name}
image: docker.io/snowdreamtech/frpc:0.61
volumeMounts:
- name: config
mountPath: "/etc/frp"
readOnly: true
volumes:
- name: config
secret:
secretName: ${name}.toml
EOF
kubectl delete -f ${tmpdir}/${FRPC_YAML} 2>/dev/null
kubectl apply -f ${tmpdir}/${FRPC_YAML}
rm -rf ${tmpdir}
}
idx=0
bind_ips=$(echo $bind_ips | tr ',' ' ')
for bind_ip in $bind_ips
do
idx=`expr $idx + 1`
install_frpc --bind_ip $bind_ip --name frpc-${idx}
done
echo "------------------------------------------------------------------"
echo "done"
echo "------------------------------------------------------------------"