Creating Services through Declarative Syntax
Explore how to define and create Kubernetes Services using declarative syntax. Understand Service types like NodePort, selectors for routing requests to pods, and how Kubernetes load balances traffic. Gain practical skills to expose applications and manage service resources in your cluster.
We'll cover the following...
Looking into the syntax
We can accomplish a similar result as the one using kubectl expose through the go-demo-2-svc.yml specification shown below:
-
Lines 1–4: Since we have already discussed the meaning of
apiVersion,kind, andmetadata, we’ll jump straight into the spec section. -
Line 5: Since we have already explored some of the options through the
kubectl exposecommand, thespecshould be relatively easy to grasp. -
Line 6: The
typeof the Service is set to NodePort, meaning that the ports will be available both within the cluster as well as from outside by sending requests to any of the nodes. ...