Be smart. Think open source.
Hands-on with what's happening in the background
apiVersion: v1
kind: Service
metadata:
labels:
app: hello-world
name: apache-hello-world
namespace: example
spec:
ports:
- name: http
port: 80
protocol: TCP
targetPort: 80
selector:
app: hello-world
$ kubectl create -f 02_service.yaml
service/apache-hello-world created
$ kubectl describe service/apache-hello-world
Name: apache-hello-world
Namespace: example
Labels: app=hello-world
Annotations: <none>
Selector: app=hello-world
Type: ClusterIP
IP: 172.16.4.19
Port: http 80/TCP
TargetPort: 80/TCP
Endpoints: 172.24.137.45
Session Affinity: None
Events: <none>
$ iptables | grep 'example/apache-hello-world'
-A KUBE-SEP-6LAKM6QVW4IKLDQJ -s 172.16.4.19/32 [...] -j KUBE-MARK-MASQ
-A KUBE-SEP-6LAKM6QVW4IKLDQJ -p tcp [...] -m tcp -j DNAT --to-destination 172.16.4.19:80
-A KUBE-SERVICES -d 172.16.4.19/32 -p tcp [...] -m tcp --dport 80 -j KUBE-SVC-33Y4WN6EIIX3LNYJ
-A KUBE-SVC-33Y4WN6EIIX3LNYJ [...] -j KUBE-SEP-6LAKM6QVW4IKLDQJ