Reprinted statement
This switched: On the ASP.NET Core on K8S learning (3) API to deploy K8S
1. Download Mirror
docker pull edisonsaonian/k8s-demo
Because the testing process is directly mentioned in the text of the mirror also pulled the local
2. Write YAML
apiVersion: apps/v1 kind: Deployment metadata: name: k8s-demo1 namespace: aspnetcore labels: name: k8s-demo1 spec: replicas: 2 selector: matchLabels: name: k8s-demo1 template: metadata: labels: name: k8s-demo1 spec: containers: - name: k8s-demo image: edisonsaonian/k8s-demo ports: - containerPort: 80 imagePullPolicy: Always --- kind: Service apiVersion: v1 metadata: name: k8s-demo1 namespace: aspnetcore spec: type: NodePort ports: - port: 80 targetPort: 80 selector: name: k8s-demo1
This deploy.yaml K8S here will tell you all the information about the API, and exposed to allow external access through what kind of way.
Note that here we create ASP.NET Core WebAPI advance the project to deploy a namespace, called the aspnetcore, so here writing namespace: aspnetcore.
K8S to distinguish between the different services through the label, so here unified name written k8s-demo.
In the multi-instance configuration, by replicas: 2 This setting tells me K8S start two instances together, of course, you can write a number greater value.
Finally, I told K8S in spec to be exposed by NodePort way out publicly accessible, so the port can range from one to know, should be within the range of 30000-32767.
3. deployed to K8S by kubectl
First, make sure your Docker for Windows and Kubernetes have started up.
Then, to complete the API in Powershell by kubectl deployment, just below this one command lines:
kubectl create -f deploy.yaml
Tips are as follows:
See above tips "service created", you can know already created, here we come again to test the following command:
kubectl get svc -n aspnetcore
It can be seen in the namespace aspnetcore, there was a k8s-demo1 service (k8s-demo before the exercise plus) up and running, and provides access through port number 30881 to the outside.
4. Verify WebApi
First, we can look at this API to access the interface via browser to see whether the normal access to.
- /api/values
- /api/values/1000