Hello everyone !! In this post, we will discuss the Kubernetes Services, What, and How we can deploy the service on a Kubernetes cluster.
What is Kubernetes Service?
Why we need Kubernetes Services?
We will get to know once we deploy the following different kinds of Kubernetes services on your Kubernetes cluster.
Types of Kubernetes Services
- NodePort
- ClusterIP
- Headless
- Loadbalancer
Kubernetes Service types |
NodePort
The node port will be a port enabled on a Node per microservice application.
Let's have pod defination in myapp.yaml
apiVersion: v1 kind: Pod metadata: name: myapp-pod labels: app: myapp spec: containers: - name: nginx-containers image: nginxCreate the myapp pod using the above defination.
Example nodeport.yaml file
apiVersion: v1 kind: Service metadata: name: appservice spec: type : NodePort ports: - port: 80 targetPort: 80 nodePort: 30008 selector: app: myapp
kubectl create -f nodeport.yaml kubctl get services kubectl describe service appservice
ClusterIP
- Headless services such as database services which are needed to be exposed to internal Kubernetes services like web application service.
apiVersion: v1 kind: Service metadata: name: app-service spec: ports: - port: 80 protocol: TCP selector: app: app-server apiVersion: apps/v1 kind: Deployment metadata: name: app-server labels: app: app-server spec: selector: matchLabels: app: app-server template: metadata: labels: app: app-server spec: containers: - name: web-server image: nginx ports: - containerPort: 80
Load balancer
You can configure a LoadBalancer on any of the Cloud provider. GCP, AWS OCI etc.
Here in the below we will consider the example of LoadBalancer using AWS cloud ELB
apiVersion: v1 kind: Service metadata: name: lb-service labels: app: lb-service spec: type: NodePort ports: - port: 80 selector: app: frontendNow we have the frontend-deployment.yml file as :
apiVersion: apps/v1 kind: Deployment metadata: name: frontend-deployment spec: replicas: 2 selector: matchLabels: app: frontend minReadySecond: 30 strategy: type: RollingUpdate rollingUpdate: maxSurge: 1 maxUnavailable: 0 template: metadata: labels: app: frontend spec: containers: - name: frontend-container image: nginx
No comments:
Post a Comment