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:

Internal Access in Kubernetes and OpenShift

  • ClusterIP (not ClusterPort): Both Kubernetes and OpenShift use a ClusterIP to expose services internally within the cluster. The ClusterIP is an internal IP address that can only be accessed from within the cluster. This is the default type of service in Kubernetes.

External Access 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.

External Access in OpenShift

  • Routes: OpenShift uses a Route object 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.

Summary

  • Internal Access: Use ClusterIP for internal access in both Kubernetes and OpenShift.
  • External Access:
    • Kubernetes: Use NodePort, LoadBalancer, or Ingress.
    • OpenShift: Use Routes.

Detailed Example

Internal Access (ClusterIP):

apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  selector:
    app: MyApp
  ports:
    - protocol: TCP
      port: 80
      targetPort: 9376
  type: ClusterIP

External Access in Kubernetes (NodePort):

apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  selector:
    app: MyApp
  ports:
    - protocol: TCP
      port: 80
      targetPort: 9376
      nodePort: 30007
  type: NodePort

External Access in Kubernetes (Ingress):

apiVersion: 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: 80

External Access in OpenShift (Route):

apiVersion: route.openshift.io/v1
kind: Route
metadata:
  name: my-route
spec:
  to:
    kind: Service
    name: my-service
  host: example.com
  port:
    targetPort: 80

Conclusion

  • 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.

⚠️ **GitHub.com Fallback** ⚠️