Implement CI / CD (Centos7.2) Series II: k8s availability cluster to build and deploy API to k8s summary
Introduction: This series of blog has been updated, the main research blog for a long time, after the experience of hands-on practice, k8s cluster is purchased five Ali cloud server deployment, this cluster do almost a week, the knowledge about k8s I also just started, knowledge of the proposed reference in this regard blog Park great God edisonchou series of articles, " the .NET Core ON K8S study and practice series index (Draft Version) ," Why do I write this series of articles, because before I work several companies have already applied a container of, .net framework applications are slowly migrating to .net core, .net core from 1.0 to start using, as a developer, what the details of some developers is closed we only know the project developed by Jenkins to build, to build the complete image pushed to HarBor, and then build a publishing tasks in Zen trail, paste the address mirroring, operation and maintenance issue just fine. I am very curious about this process, spare time is also studying this stuff. Well, let us talk to here, Here I will share your own experiences k8s built in clusters, there is something wrong please correct to say also.
A, k8s build a high-availability cluster summary
We all know Kubernetes itself, focusing on stability, scalability, security; small changes in the core strategy; surrounding ecosystem continued to erupt. k8s built in three ways: (1) community-based programs: messy, unreliable, difficult to upgrade (2) kubeadm: elegant, simple, support high availability, easy to upgrade, easy to maintain, the document is not detailed enough (3) binary deployment, recommend early scholars using binary structures, because they can quickly give up, ha ha ha, joking aside, binary way easy to maintain, flexible and easy to upgrade. I used the k8s cluster binary built, Ali cloud configuration 5 sets as follows:
Environmental parameters: k8s 1.14.0 Docker 17.03.1-ce Harbor 1.6.0 Jenkins v2.150.2, must pay attention to the problem version,
Note: Using cloud servers skipped keepalived configuration, do not use virtual ip (cloud environments generally do not support their own definition virtual ip) directly to the virtual ip set as the first master of ip on it.
PS: If high availability is a must, then you can buy cloud load balancing service providers (such as Ali cloud SLB), the backends set your three master node, then it is configured virtual ip load balancing within the network to ip .
Specific details of cluster structures, I will not be listed, because not the point.
Second, the deployment WebAPI to k8s
- Preparation Deployment YAML
This YAML file, quoted from Edison Zhou ( https://www.cnblogs.com/edisonchou/p/aspnet_core_on_k8s_firststudy_part3.html ), where we use the Edison Zhou mirroring warehouse
apiVersion: apps/v1 kind: Deployment metadata: name: k8s-demo namespace: aspnetcore labels: name: k8s-demo spec: replicas: 2 selector: matchLabels: name: k8s-demo template: metadata: labels: name: k8s-demo spec: containers: - name: k8s-demo image: edisonsaonian/k8s-demo ports: - containerPort: 80 imagePullPolicy: Always --- kind: Service apiVersion: v1 metadata: name: k8s-demo namespace: aspnetcore spec: type: NodePort ports: - port: 80 targetPort: 80 selector: name: k8s-demo
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.
- Deployed to k8s by kubectl
We need to have execute the following command:
kubectl create namespace aspnetcore // create a namespace "aspnetcore"
mkdir aspnetcore
aspnetcore CD / Vim deploy.yaml the above configuration // write the file kubectl create -f deploy.yaml
[root@m7-a2-15-43 aspnetcore]# kubectl get svc -n aspnetcore NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE k8s-demo NodePort 10.254.180.117 <none> 80:8671/TCP 4h55m
Can be seen in the namespace aspnetcore, there is a k8s-demo of the service up and running, and provides access to the outside through port number 8671.
- Verify that you can access WebAPI
First, visit the API interface in a browser to see if normal visit: http: // public IP: 8671 / api / values
Then, we then to the Dashboard, look at the state of k8s-demo:
We click on the namespace selection: aspnetcore
Of course, you can also click: "namespace" a "cluster" option below, click on the corresponding name, which you can see detailed information. You can see more detailed information from the Dashboard, Deployment, container group (due to the replicas we set = 2, so there will be two containers up and running), including a replica set, and so run, you can also real-time Dashboard preliminary we monitor the operation of the API.
- By Dashboard telescopic WebAPI
In the Dashboard, we can visually our Deployment telescopic container instance, the specific operation, see: https://www.cnblogs.com/edisonchou/p/aspnet_core_on_k8s_firststudy_part3.html , I will not say any more.
Third, the summary
In this paper, a brief summary of what use to deploy high-availability k8s Ali cloud clusters, some students said how could not write in detail about the process of deploying it? Owing to time constraints, the Moreover, the theme of the deployment process and this series does not match, you can refer to other articles about the Dashboard, the enterprise is generally not used, since the inquiry process is still finishing documents deployed, only you need to know can be. The purpose of this article is to let you experience the so-called container arrangement, and asp.net core on k8s. The author is also new to, there is a lot to learn, it's just k8s a little bit, because have not used a production environment, you need to observe a period of time, late, I tidy up the deployment process, and then to others. Advance notice about the theme of the blog articles: Jenkins + k8s, implement CI / CD, so stay tuned.
This is a project of the Department of class blog to use: https://github.com/guozheng007/asp.net-core2.1-miaosha-project
References:
Edison Zhou:https://www.cnblogs.com/edisonchou/p/aspnet_core_on_k8s_firststudy_part3.html
Liu fruit country: https://coding.imooc.com/class/335.html (fee-paying courses 366.00)