serving the solutions day and night

Pages

Monday, August 17, 2020

Create a Kubernetes service using a YAML

Instead of exposing directly (see the blog), create a service in a declarative way using a YAML file

forntendmvc_service .yaml

--- 
apiVersion: v1
kind: Service
metadata: 
 name: myapp-svc
spec: 
  selector:
    app:myapp
  type: NodePort
  ports:
    - port:80
      nodePort: 30001
  • The selector, to indicate which pods will be exposed.
    • "app: myapp" - is one of the labels of the pods. (see the POD blog)
    • Labels in K8s are not only a way to add some information to elements, but are also used to connect them.  
    • In this case, connecting the service with the pods, and tell the system to select all pods that have the label myapp for the service.
    • To select the pods, you can also use all the labels in the selector
  • The service type, NodePort and the ports mapping, in this case, the HTTP port 80 and NodePort 30001 of the cluster. 

Delete the previous service(see the blog) 

kubectl delete service myapp-rc-service

Create the service using a YAML script 

kubectl create -f forntendmvc_service .yaml

Browse the site, http://localhost:30001


1 comment:

bhanu sreee said...

This is an amazing blog, thank you so much for sharing such valuable information with us.
Workday Integration Training
Workday Integration Online Training