Creating Services through Declarative Syntax
Learn to create Services through declarative syntax.
We'll cover the following...
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:
apiVersion: v1kind: Servicemetadata:name: go-demo-2spec:type: NodePortports:- port: 28017nodePort: 30001protocol: TCPselector:type: backendservice: go-demo-2
-
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. ...