expose nginx-ingress TCP-Service on port 9000
This commit is contained in:
parent
bd2095e5e2
commit
6cff7d1f9d
106
README.md
106
README.md
@ -20,7 +20,7 @@ finally `systemctl daemon-reload` and `systemctl restart k3s`
|
|||||||
### Installation
|
### Installation
|
||||||
https://kubernetes.github.io/ingress-nginx/deploy/#bare-metal
|
https://kubernetes.github.io/ingress-nginx/deploy/#bare-metal
|
||||||
|
|
||||||
### Switch ingress-Service from NodePort to LoadBalancer
|
### Change service type from NodePort to LoadBalancer
|
||||||
`kubectl edit service -n ingress-nginx` and change `type: NodePort` to `type: LoadBalancer`
|
`kubectl edit service -n ingress-nginx` and change `type: NodePort` to `type: LoadBalancer`
|
||||||
|
|
||||||
Port 80 and 443 should listen now on an *External-IP* `kubectl get all --all-namespaces`:
|
Port 80 and 443 should listen now on an *External-IP* `kubectl get all --all-namespaces`:
|
||||||
@ -72,3 +72,107 @@ spec:
|
|||||||
env:
|
env:
|
||||||
[...]
|
[...]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Deploy nginx-service and expose via nginx-ingress on TCP-port 9000
|
||||||
|
my-nginx-deployment.yml:
|
||||||
|
```
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: my-nginx
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
run: my-nginx
|
||||||
|
replicas: 1
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
run: my-nginx
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: my-nginx
|
||||||
|
image: nginx:alpine
|
||||||
|
ports:
|
||||||
|
- containerPort: 80
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: my-nginx
|
||||||
|
labels:
|
||||||
|
run: my-nginx
|
||||||
|
spec:
|
||||||
|
ports:
|
||||||
|
- port: 80
|
||||||
|
protocol: TCP
|
||||||
|
selector:
|
||||||
|
run: my-nginx
|
||||||
|
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: tcp-services
|
||||||
|
namespace: ingress-nginx
|
||||||
|
data:
|
||||||
|
9000: "default/my-nginx:80::PROXY"
|
||||||
|
```
|
||||||
|
Apply with `kubectl apply -f my-nginx-deployment.yml`:
|
||||||
|
```
|
||||||
|
deployment.apps/my-nginx created
|
||||||
|
service/my-nginx created
|
||||||
|
configmap/tcp-services created
|
||||||
|
```
|
||||||
|
Test: `kubectl get all`:
|
||||||
|
```
|
||||||
|
[...]
|
||||||
|
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
|
||||||
|
[...]
|
||||||
|
service/my-nginx ClusterIP 10.43.118.13 <none> 80/TCP 99s
|
||||||
|
[...]
|
||||||
|
```
|
||||||
|
Expose my-nginx app on nginx-ingress TCP-port 9000: `kubectl edit service -n ingress-nginx`
|
||||||
|
|
||||||
|
```
|
||||||
|
spec:
|
||||||
|
clusterIP: 10.43.237.255
|
||||||
|
externalTrafficPolicy: Cluster
|
||||||
|
ports:
|
||||||
|
- name: http
|
||||||
|
nodePort: 30312
|
||||||
|
port: 80
|
||||||
|
protocol: TCP
|
||||||
|
targetPort: http
|
||||||
|
- name: https
|
||||||
|
nodePort: 30366
|
||||||
|
port: 443
|
||||||
|
protocol: TCP
|
||||||
|
targetPort: https
|
||||||
|
*** ADD >>>
|
||||||
|
- name: proxied-tcp-9000
|
||||||
|
port: 9000
|
||||||
|
protocol: TCP
|
||||||
|
targetPort: 9000
|
||||||
|
<<< ADD ***
|
||||||
|
[...]
|
||||||
|
```
|
||||||
|
Verify nginx-ingress is listening on port 9000 with `kubectl get all --all-namespaces`:
|
||||||
|
```
|
||||||
|
[...]
|
||||||
|
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
|
||||||
|
[...]
|
||||||
|
ingress-nginx service/ingress-nginx-controller LoadBalancer 10.43.237.255 10.62.94.246 80:30312/TCP,443:30366/TCP,9000:31460/TCP 71m
|
||||||
|
[...]
|
||||||
|
```
|
||||||
|
Test:
|
||||||
|
```
|
||||||
|
dominik@muggler:~$ curl -s http://10.62.94.246:9000
|
||||||
|
<html>
|
||||||
|
<head><title>400 Bad Request</title></head>
|
||||||
|
<body>
|
||||||
|
<center><h1>400 Bad Request</h1></center>
|
||||||
|
<hr><center>nginx/1.19.2</center>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
```
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user