Category : Kubernetes | Sub Category : Kubernetes With Java | By Prasad Bonam Last updated: 2024-01-30 10:16:56 Viewed : 162
In Kubernetes, services are used to expose applications and services to other components within the cluster or external systems. There are several types of services in Kubernetes, each serving a different purpose. Here are the common service types:
ClusterIP:
yamlkind: Service
apiVersion: v1
metadata:
name: my-service
spec:
selector:
app: my-app
ports:
- protocol: TCP
port: 80
targetPort: 8080
type: ClusterIP
NodePort:
yamlkind: Service
apiVersion: v1
metadata:
name: my-service
spec:
selector:
app: my-app
ports:
- protocol: TCP
port: 80
targetPort: 8080
type: NodePort
LoadBalancer:
yamlkind: Service
apiVersion: v1
metadata:
name: my-service
spec:
selector:
app: my-app
ports:
- protocol: TCP
port: 80
targetPort: 8080
type: LoadBalancer
ExternalName:
yamlkind: Service
apiVersion: v1
metadata:
name: my-service
spec:
type: ExternalName
externalName: my.external.service
Headless:
yamlkind: Service
apiVersion: v1
metadata:
name: my-service
spec:
selector:
app: my-app
clusterIP: None
These service types provide flexibility in exposing and accessing applications within a Kubernetes cluster. The appropriate type depends on the specific requirements and use case of your application.