title
stringlengths 3
46
| content
stringlengths 0
1.6k
|
---|---|
22:250 | |
22:251 | You can verify that your images have been correctly loaded by listing all the images loaded in Minikube: |
22:252 | minikube image ls |
22:253 | |
22:254 | Now, we need to define a .yaml Kubernetes configuration file with two deployments and a service that forwards communications to grpcmicroservice, which is the only microservice acting as a server. Let’s call it minikubedeploy.yaml. |
22:255 | The definition of the grpcmicroservice deployment is straightforward: |
22:256 | apiVersion: apps/v1 |
22:257 | kind: Deployment |
22:258 | metadata: |
22:259 | name: grpcmicroservice |
22:260 | labels: |
22:261 | app: statistics |
22:262 | spec: |
22:263 | selector: |
22:264 | matchLabels: |
22:265 | app: statistics |
22:266 | role: worker |
22:267 | replicas: 1 |
22:268 | template: |
22:269 | metadata: |
22:270 | labels: |
22:271 | app: statistics |
22:272 | role: worker |
22:273 | spec: |
22:274 | containers: |
22:275 | - name: grpcmicroservice |
22:276 | image: grpcmicroservice:latest |
22:277 | imagePullPolicy: Never |
22:278 | resources: |
22:279 | requests: |
22:280 | cpu: 10m |
22:281 | memory: 10Mi |
22:282 | env: |
22:283 | - name: ASPNETCORE_HTTP_PORTS |
22:284 | value: `8080` |
22:285 | ports: |
22:286 | - containerPort: 8080 |
22:287 | name: http |
22:288 | |
22:289 | The code above requires just one replica, but you can experiment with two or three replicas. The ASPNETCORE_HTTP_PORTS environment variable is a standard ASP.NET setting that informs Kestrel on the HTTP port where to listen. |
22:290 | |
22:291 | The imagePullPolicy: Never setting specifies the image caching policy within the Kubernetes cluster. It prevents Minikube from trying to download a fresher version of the image from the original source into its cache. We need this setting, since there is no “original source” containing our image because we uploaded the image directly to the Minikube cache with the minikube image load command. |
22:292 | You must always specify this setting when images are not available in a shared image repository but are uploaded directly to the Minikube cache from the Docker Desktop local repository. Shared images, instead, do not need to be uploaded manually in the Minikube cache but can be simply referenced with their full URL in the Kubernetes .yaml file. |
22:293 | |
22:294 | All other settings are quite standard. |
22:295 | The definition of the fakesource deployment is completely analogous but doesn’t contain information about the container ports, since this microservice doesn’t act as a server: |
22:296 | apiVersion: apps/v1 |
22:297 | kind: Deployment |
22:298 | metadata: |
22:299 | name: fakesource |
22:300 | labels: |
22:301 | app: sale |
22:302 | spec: |
22:303 | selector: |
22:304 | matchLabels: |
22:305 | app: sales |
22:306 | role: source |
22:307 | replicas: 1 |
22:308 | template: |
22:309 | metadata: |
22:310 | labels: |
22:311 | app: sales |
22:312 | role: source |
22:313 | spec: |
22:314 | containers: |
22:315 | - name: fakesource |
22:316 | image: fakesource:latest |
22:317 | imagePullPolicy: Never |
22:318 | resources: |
22:319 | requests: |
22:320 | cpu: 10m |
22:321 | memory: 10Mi |
22:322 | |
22:323 | The definition of the service that forwards communications to grpcmicroservice is quite standard: |
22:324 | apiVersion: v1 |
22:325 | kind: Service |
22:326 | metadata: |
22:327 | name: grpcmicroservice |
22:328 | labels: |
22:329 | app: contract |
22:330 | role: worker |
22:331 | spec: |
22:332 | ports: |
22:333 | - port: 8080 |
22:334 | name: http |
22:335 | protocol: TCP |
22:336 | targetPort: 8080 |
22:337 | selector: |
22:338 | app: statistics |
22:339 | role: worker |
22:340 | |
22:341 | You must pay attention only to the port numbers that must be coherent in all settings and to the service name, since they will be used in the URLs of all communication to the grpcmicroservice. |
22:342 | |
22:343 | If the service names match the hostnames in the Docker virtual network, the URLs will work both in Kubernetes and the Docker virtual network. So, you don’t need to modify any code or configuration to adapt the code that runs in the Docker virtual network to Minikube or any other Kubernetes clusters. |
22:344 | |
22:345 | The whole minkubedeploy.yaml file is available in the ch22 folder of the GitHub repository associated with the book. |
22:346 | Now, let’s open a Windows prompt in the folder that contains the minkubedeploy.yaml file, issuing the command below that will load the application configuration in the Minikube cluster: |
22:347 | kubectl create -f minkubedeploy.yaml |
22:348 | |
22:349 | Then, issue the kubectl get deployment command to verify that all deployments have been correctly defined and are running. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.