ClusterIP NodeIP NodePort , in Open shift and Kubernets - unix1998/technical_notes GitHub Wiki
OpenShift and Kubernetes use different mechanisms for internal and external access to services. Here’s a detailed explanation:
-
ClusterIP (not ClusterPort): Both Kubernetes and OpenShift use a
ClusterIPto expose services internally within the cluster. TheClusterIPis an internal IP address that can only be accessed from within the cluster. This is the default type of service in Kubernetes.
-
NodePort: When a service is exposed externally using a
NodePort, Kubernetes allocates a port on each node (within a range typically 30000-32767). The service can then be accessed via<NodeIP>:<NodePort>. - LoadBalancer: This type of service creates an external load balancer (if supported by the cloud provider) that forwards traffic to the service.
- Ingress: Ingress resources allow HTTP and HTTPS routing to services based on the URL. Ingress controllers, which are usually installed in the cluster, manage the routing rules.
-
Routes: OpenShift uses a
Routeobject to expose services externally. Routes provide a way to access the service from outside the cluster via HTTP/HTTPS. A route consists of a hostname (and optionally a path) that maps to a service.
-
Internal Access: Use
ClusterIPfor internal access in both Kubernetes and OpenShift. -
External Access:
-
Kubernetes: Use
NodePort,LoadBalancer, orIngress. -
OpenShift: Use
Routes.
-
Kubernetes: Use
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app: MyApp
ports:
- protocol: TCP
port: 80
targetPort: 9376
type: ClusterIPapiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app: MyApp
ports:
- protocol: TCP
port: 80
targetPort: 9376
nodePort: 30007
type: NodePortapiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-ingress
spec:
rules:
- host: example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: my-service
port:
number: 80apiVersion: route.openshift.io/v1
kind: Route
metadata:
name: my-route
spec:
to:
kind: Service
name: my-service
host: example.com
port:
targetPort: 80- ClusterIP is used for internal access in both Kubernetes and OpenShift.
- NodePort, LoadBalancer, and Ingress are used for external access in Kubernetes.
- Routes are used for external access in OpenShift.
Therefore, while NodePort can be used for external access, OpenShift typically uses Routes for this purpose.