- Take me to Lecture
In this section, we will take a look at Service Networking
- ClusterIP
clusterIP.yaml
apiVersion: v1
kind: Service
metadata:
name: local-cluster
spec:
ports:
- port: 80
targetPort: 80
selector:
app: nginx
- NodePort
nodeportIP.yaml
apiVersion: v1
kind: Service
metadata:
name: nodeport-wide
spec:
type: NodePort
ports:
- port: 80
targetPort: 80
selector:
app: nginx
$ kubectl create -f clusterIP.yaml
service/local-cluster created
$ kubectl create -f nodeportIP.yaml
service/nodeport-wide created
$ kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx 1/1 Running 0 1m 10.244.1.3 node01 <none> <no
$ kubectl get service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 5m22s
local-cluster ClusterIP 10.101.67.139 <none> 80/TCP 3m
nodeport-wide NodePort 10.102.29.204 <none> 80:30016/TCP 2m
$ ps -aux | grep kube-apiserver
--secure-port=6443 --service-account-key-file=/etc/kubernetes/pki/sa.pub --
service-cluster-ip-range=10.96.0.0/12
$ iptables -L -t nat | grep local-cluster
KUBE-MARK-MASQ all -- 10.244.1.3 anywhere /* default/local-cluster: */
DNAT tcp -- anywhere anywhere /* default/local-cluster: */ tcp to:10.244.1.3:80
KUBE-MARK-MASQ tcp -- !10.244.0.0/16 10.101.67.139 /* default/local-cluster: cluster IP */ tcp dpt:http
KUBE-SVC-SDGXHD6P3SINP7QJ tcp -- anywhere 10.101.67.139 /* default/local-cluster: cluster IP */ tcp dpt:http
KUBE-SEP-GEKJR4UBUI5ONAYW all -- anywhere anywhere /* default/local-cluster: */
- May this file location is vary depends on your installation process.
$ cat /var/log/kube-proxy.log