Endpoint-k8S
Jump to navigation
Jump to search
appCfg="50 app1
51:6443 app2
52:8081 app3"
networkZone=192.168.1
cluster_domain=domain-example
yum install nc -y
echo "${appCfg}" |\
sed -rn 's#^([12]?[0-9]{,2})(|:([0-9]{1,5}))[[:space:]]+([^[:space:]]+)(|[[:space:]].*)$#'"${networkZone}"'.\1:\3:\4#p' |\
while IFS=':' read IP_source port_source hostName ;do
if [ -z "${port_source}" ] ;then
if nc -zw1 ${IP_source} 443 ;then
port_source=443
else
port_source=80
fi
fi
SERVICE_NAME="${hostName}"
cat <<EOF | oc apply -f -
kind: "Service"
apiVersion: "v1"
metadata:
name: "${SERVICE_NAME}"
spec:
ports:
-
name: "${SERVICE_NAME}"
protocol: "TCP"
port: ${port_source}
targetPort: ${port_source}
# nodePort: 0
#selector: '{}'
---
kind: "Endpoints"
apiVersion: "v1"
metadata:
name: "${SERVICE_NAME}"
subsets:
-
addresses:
-
ip: ${IP_source}
ports:
-
port: ${port_source}
name: "${SERVICE_NAME}"
EOF
kubectl delete route.route.openshift.io/${SERVICE_NAME}
if [ ${port_source} -eq 443 ] ||[ ${port_source} -eq 5000 ];then
oc create route passthrough --service=${SERVICE_NAME} --hostname=${SERVICE_NAME}.apps.${cluster_domain}
else
oc create route edge --service=${SERVICE_NAME} --hostname=${SERVICE_NAME}.apps.${cluster_domain} #--cert=/etc/letsencrypt/live/apps.${cluster_domain}/fullchain.pem --key=/etc/letsencrypt/live/apps.${cluster_domain}/privkey.pem #--ca-cert=ca.crt
fi
kubectl get route.route.openshift.io/${SERVICE_NAME}
done