concept kubectl in category microservice

appears as: kubectl, kubectl, The kubectl, The kubectl
Microservices in .NET Core, Second Edition

This is an excerpt from Manning's book Microservices in .NET Core, Second Edition.

This will install and start the Kubernetes cluster. Furthermore this installs the microk8s command line interface which includes the kubectl command that we are going to use. To make it a bit easier to follow along with the work in the following sections you can create an alias for kubectl:

Figure 3.5. Docker Desktop Kubernetes settings
ch03 fig 05 horsdal2

Once the Loyalty Program API and the Special Offers microservice is deploy we should se both running in Kubernetes both in the Kubernetes dashboard (which we configured in chapter 3) and in the kubectl command line:

We can also see from this that the Loyalty Program event consumer by looking at the last shedule column. In my case the cron job has been triggered 20 seconds ago.

We can also see a list of recent invocation of the Loyalty Program event consumer by looking at the Kubernetes jobs list:

> kubectl get jobs
NAME                                  COMPLETIONS   DURATION   AGE
loyalty-program-consumer-1590755940   1/1           2s         11s
loyalty-program-consumer-1590757080   1/1           2s         1m11s
loyalty-program-consumer-1590757140   1/1           3s         2m11s

This concludes the deployment of the Loyalty Program microservice. The API part as well as the event consumers part is running in our Kubernetes cluster in AKS. The Kubernetes manifest we have created for the Loyalty Program is the template for the manifests for all the microservices we will create, only the container images will have different name and the event consumer schedules will vary.

Microservices Security in Action

This is an excerpt from Manning's book Microservices Security in Action.

\> kubectl apply -f sts.deployment.yaml


deployment.apps/sts-deployment created

The communications among all these components happen via the API server. For example, to deploy a container in Kubernetes, we need to talk to the API server via a Kubernetes client application, which is called a kubectl. We discuss all four components in a master node in detail later in the appendix.

To interact with the Kubernetes environment running on Google Cloud, you also need to install kubectl as a component of the gcloud tool, which you installed in section J.5.1. This command-line tool, kubectl, runs on your local computer and talks to the Kubernetes API server running on Google Cloud to perform certain operations. The following command installs kubectl as a component of the gcloud tool:

\> gcloud components install kubectl

J.18.1 How kubectl run works

The best way to understand how Kubernetes internal communication happens is to go through one simple command and see how it works end to end (see figure J.4). In section J.6, we used the following kubectl command to create a Kubernetes Deployment with the Docker image gcr.io/google-samples/hello-app:

\> kubectl run hello-server --image gcr.io/google-samples/hello-app:1.0 \
--port 8080

When we run this command from kubectl running on our local machine, it creates a request with the provided parameters and talks to an API running on the Kubernetes API server. The communications among all the components in the Kubernetes control plane happens via the API server.

Figure J.4 A request generated by kubectl passes through the authentication, authorization, and admission controller plugins of the API server. It’s validated and then stored in etcd. The scheduler and kubelet respond to events generated by the API server.

The following lists the sequence of events in figure J.4 that happen in a Kubernetes cluster after the API server receives a request from kubectl: