by Anish
Posted on Tuesday August 15, 2018
Many Services
need to expose more than one port. Kubernetes supports multiple port definitions on a Service
object. When using multiple ports you must give all of your ports names, so that endpoints can be disambiguated. For example, this definition is used in nginx secure deployment in my previous article
apiVersion: v1
kind: Service
metadata:
name: nginxsvc
labels:
app: nginx
spec:
type: NodePort
ports:
- port: 80
protocol: TCP
name: http
- port: 443
protocol: TCP
name: https
selector:
app: nginx
--service-node-port-range flag (default: 30000-32767)
, and each Node will proxy that port (the same port number on every Node) into your Service
These are IPtables rules in which will be setup by kubernetes in the master-node.
iptables -t nat --line-numbers -n -L | grep 30287
1 KUBE-MARK-MASQ tcp -- 0.0.0.0/0 0.0.0.0/0 /* default/nginxsvc:https */ tcp dpt:**30287**
2 KUBE-SVC-ER5WGNLE726ZPUG2 tcp -- 0.0.0.0/0 0.0.0.0/0 /* default/nginxsvc:https */ tcp dpt:**30287**
iptables -L | grep 30287
REJECT tcp -- anywhere anywhere /* default/nginxsvc:https has no endpoints */ ADDRTYPE match dst-type LOCAL tcp dpt:**30287** reject-with icmp-port-unreachable
kubectl get service nginxsvc -o json
"spec": {
"clusterIP": "10.103.250.179",
"externalTrafficPolicy": "Cluster",
"ports": [
{
"name": "http",
"nodePort": 32210,
"port": 80,
"protocol": "TCP",
"targetPort": 80
},
{
"name": "https",
"nodePort": 30287,
"port": 443,
"protocol": "TCP",
"targetPort": 443
}
],
Thanku for reading !!! Give a Share for Support
Asking for donation sound bad to me, so i'm raising fund from by offering all my Nine book for just $9