0% found this document useful (0 votes)
90 views22 pages

Kubernetes Services

The document discusses different types of Kubernetes services, including NodePort and ClusterIP services. A NodePort service exposes a service on each Node's IP at a static port. It maps a service port to a node port in the range 30000-32767. A ClusterIP service exposes the service only internally within the cluster. It assigns a cluster-internal IP address for accessing the service. The document provides examples of YAML definitions for NodePort and ClusterIP services and how to create and access them. It also discusses using a LoadBalancer service to make the service accessible externally by provisioning load balancers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views22 pages

Kubernetes Services

The document discusses different types of Kubernetes services, including NodePort and ClusterIP services. A NodePort service exposes a service on each Node's IP at a static port. It maps a service port to a node port in the range 30000-32767. A ClusterIP service exposes the service only internally within the cluster. It assigns a cluster-internal IP address for accessing the service. The document provides examples of YAML definitions for NodePort and ClusterIP services and how to create and access them. It also discusses using a LoadBalancer service to make the service accessible externally by provisioning load balancers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Services

mumshad mannambeth
Services
Services

Se

es
r

v ic
v ic
es

r
Se

Services
Service
192.168.1.2

10.244.0.0
SSH
>curl http://10.244.0.2
>curl http://192.168.1.2 :30008

30008
Service
?
Hello World!
Hello World!

10.244.0.2

192.168.1.10
POD

Node
Services Types

NodePort ClusterIP LoadBalancer


NodePort
Service - NodePort
192.168.1.2

10.244.0.0

>curl http://192.168.1.2:30008

30008
Hello World! Service
?
10.244.0.2

192.168.1.10
POD

Node
Service - NodePort

2 Port

10.106.1.12
1 TargetPort
30008

3 NodePort Service

80
Range: 80
30000 - 32767 10.244.0.2

POD

Node
Service - NodePort
service-definition.yml
apiVersion: v1
kind: Service
metadata:
name: myapp-service
2 Port
10.106.1.12

1 TargetPort
30008

3 NodePort Service spec:


80

Range: 80 type: NodePort


30000 - 32767 10.244.0.2 ports:
- targetPort: 80
* port: 80
nodePort: 30008

POD

Node
Service - NodePort
service-definition.yml pod-definition.yml
apiVersion: v1 > kubectl apiVersion: v1
create –f service-definition.yml
kind: Service kind: Pod
service "myapp-service" created

metadata:
> kubectl get services
name: myapp-service metadata:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes
name:
ClusterIP
myapp-pod
10.96.0.1 <none> 443/TCP 16d
spec: labels:
myapp-service
NodePort 10.106.127.123 <none> 80:30008/TCP 5m
type: NodePort app: myapp
ports: type: front-end
> curl http://192.168.1.2:30008
- targetPort: 80 spec:
port: 80 containers:
nodePort: 30008 - name: nginx-container
selector: image: nginx
Service - NodePort

192.168.1.2 30008

selector:
Service
app: myapp
Algorithm: Random
SessionAffinity: Yes

10.244.0.3 10.244.0.2 10.244.0.4

labels:
app: myapp
POD POD POD

Node
Service - NodePort
>curl http://192.168.1.2:30008

>curl http://192.168.1.3:30008

>curl http://192.168.1.4:30008

192.168.1.2 30008 192.168.1.3 30008 192.168.1.4 30008

Service

10.244.0.3 10.244.0.2 10.244.0.4

POD POD POD

Node Node Node


Demo
Service - NodePort
ClusterIP

mumshad mannambeth
ClusterIP
10.244.0.3 10.244.0.2 10.244.0.4

front-end POD POD POD

back-end

10.244.0.5 10.244.0.6 10.244.0.7

back-end
POD POD POD

redis
10.244.0.8
10.244.0.5 10.244.0.9 10.244.0.10

redis
POD POD POD
service-definition.yml pod-definition.yml
apiVersion: v1 > kubectl apiVersion: v1
create –f service-definition.yml
kind: Service kind: Pod
service “back-end" created

metadata:
> kubectl get services
name: back-end metadata:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes
name: myapp-pod
ClusterIP 10.96.0.1 <none> 443/TCP 16d
spec: back-end labels:
ClusterIP 10.106.127.123 <none> 80/TCP 2m
type: ClusterIP app: myapp
ports: type: back-end
- targetPort: 80 spec:
port: 80 containers:
- name: nginx-container
selector: image: nginx
Service
8080

Voting-app-Pod
Not specified in source code.
Default 6379 assumed

6379
apiVersion: v1
Redis kind: Service
Service metadata:
name: redis
spec:
ports:
6379 - port: 6379
targetPort: 6379
selector:
redis-pod name: redis-pod
app: demo-voting-app
Service
8080

Voting-app-Pod

7000
apiVersion: v1
Redis kind: Service
Service metadata:
name: some-redis-service
spec:
ports:
6379 - port: 7000
targetPort: 6379
selector:
redis-pod name: redis-pod
app: demo-voting-app
Demo
Service - NodePort
References
https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/
Service -
LoadBalancer

mumshad mannambeth
>curl http://192.168.1.2:30008

Services >curl http://myapp.com >curl http://192.168.1.3:30008

>curl http://192.168.1.4:30008

Load
Native Balancer
Load Balancer

192.168.1.2 30008 192.168.1.3 30008 192.168.1.4 30008

Service - NodePort

10.244.0.3 10.244.1.3 10.244.2.3

POD POD POD

Service - ClusterIP

10.244.0.4 10.244.1.4 10.244.2.4

POD POD POD

Node Node Node


service-definition.yml
apiVersion: v1 > kubectl create –f service-definition.yml
kind: Service service “front-end" created

metadata:
> kubectl get services
name: front-end
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 16d
spec: front-end LoaBalancer 10.106.127.123 <Pending> 80/TCP 2m
type: NodePort
LoadBalancer
ports:
- targetPort: 80
port: 80

selector:
app: myapp
type: front-end

You might also like