Create a Service - The Imperative Way
Let's look at the imperative way of creating a Service..
We'll cover the following...
In this chapter, we’ll be creating and working with LoadBalancer Services, and you can use any of the clusters. If the cluster is in the cloud, you’ll provision one of the cloud’s internet-facing load balancers and will work with public IPs or public DNS names. If you’re using the cluster provided in the course, the experience will be the same, but we’ll use local constructs such as localhost
.
Working with Services imperatively
We’ll create a deployment using the deploy.yml
file provided in the below widget. We’ll then create a Service imperatively for this Deployment.
apiVersion: apps/v1 kind: Deployment metadata: name: svc-test spec: replicas: 10 selector: matchLabels: chapter: services template: metadata: labels: chapter: services spec: containers: - name: hello-ctr image: nigelpoulton/k8sbook:1.0 ports: - containerPort: 8080
The kubectl expose
command creates a Service for an existing Deployment. It’s intelligent enough to inspect the running Deployment and create all the required constructs, such as IP address, DNS records, and correct port mappings.
Run the following command to create a new LoadBalancer Service for the Pods in the svc-test Deployment.
$ kubectl expose deployment svc-test --type=LoadBalancerservice/svc-test exposed
Run the ...