当前位置:网站首页>How to deploy applications on kubernetes cluster
How to deploy applications on kubernetes cluster
2022-07-03 17:41:00 【a_ small_ cherry】
brief introduction : In this article, we will introduce how to Kubernetes Create a remote image on the cluster , And use the image deployment service through the command line .
Image download 、 Domain name resolution 、 Time synchronization please click Alibaba open source mirror site
Preface
In this paper , We will learn how to deploy a simple application in a cluster .
We can set k8s Deployment configuration for , To control k8s How to create and update your application instances , Once the deployment settings are created , The main node of the cluster will schedule application instances according to your configuration , Deployed on each node of the cluster .
After deployment ,k8s It will continue to monitor the running status of the application instance on each node , Once there is downtime 、 Deleted, etc ,k8s New application instances will be created on other nodes of the cluster , To meet your deployment configuration settings . This is also different from the previous deployment methods , utilize k8s Deploy the application , It can help you improve the high availability of the system .
Prepare the mirror
First, we need to prepare an application image , because k8s The application of the upper deployment needs to be containerized .
You can directly use my built registry.cn-hangzhou.aliyuncs.com/larswang/hello-node:1.0
Mirror image , Skip this paragraph , Look directly at establish Deployment .
You can also refer to the following methods Build your own mirror image .
Let's use docker Create a simple NodeJS Service image .( If not already installed docker Your friends can use Alibaba cloud image source Download and install ).
Code preparation
You can use it directly hello-node Content of code warehouse
server.js
var http = require('http');
var handleRequest = function(request, response) {
console.log('Received request for URL: ' + request.url);
response.writeHead(200);
response.end('Hello World!');
};
var www = http.createServer(handleRequest);
www.listen(8080);
Dockerfile
FROM node:6.14.2
EXPOSE 8080
COPY server.js .
CMD [ "node", "server.js" ]
Build a mirror image
I use Alibaba cloud's image warehouse : Access now
Create a mirror repository
Associated source code
Build immediately
Building a successful
Local pull
docker pull registry.cn-hangzhou.aliyuncs.com/larswang/hello-node:1.0
docker run --name node-test -p 8080:8080 -d registry.cn-hangzhou.aliyuncs.com/larswang/hello-node:1.0
Local access :http://localhost:8080/
, You can see Hello World! Output . Explain the image construction OK.
Deployment
Deployment It is used to deploy stateless applications , That is, describe the stateless application cluster state , Such as setting deployment 5 Copies , When one of the replicas goes down , Will automatically expand to 5 Copies .
kubectl create deployment hello-node --image=registry.cn-hangzhou.aliyuncs.com/larswang/hello-node:1.0
see deployment
kubectl get deployments
see pod
kubectl get pods
Service
Default Pod Only through Kubernetes Inside the cluster IP Address access , In order to carry on Kubernetes External access to virtual networks , Need to put Pod Exposure to Kubernetes Service.
kubectl expose deployment hello-node --type=LoadBalancer --port=8080
adopt LoadBalancer Type of way will cluster services 8080 Ports exposed .
see Services
kubectl get services
visit Service
minikube service hello-node
The browser will automatically open http://127.0.0.1:51284
, Show Hello World!
clear
You can clean up the resources created in the cluster with the following commands .
kubectl delete service hello-node
kubectl delete deployment hello-node
summary
In this article, we introduced how to create a remote image , And use the image deployment service through the command line .
In this paper, from : How to be in Kubernetes Deploy applications on the cluster - Alicloud developer community
边栏推荐
- 1164 Good in C
- SWM32系列教程4-端口映射及串口应用
- Embedded-c language-7
- [vscode] convert tabs to spaces
- 远程办公工具分享|社区征文
- 【JokerのZYNQ7020】DDS_ Compiler。
- How to train mask r-cnn model with your own data
- MySQL has been stopped in the configuration interface during installation
- [combinatorics] recursive equation (four cases where the non-homogeneous part of a linear non-homogeneous recursive equation with constant coefficients is the general solution of the combination of po
- Collection of the most beautiful graduation photos in the graduation season, collection of excellent graduation photos
猜你喜欢
Golang unit test, mock test and benchmark test
Kubernetes resource object introduction and common commands (4)
How to purchase Google colab members in China
Kubernetes resource object introduction and common commands (III)
How to read the source code [debug and observe the source code]
鸿蒙第四次培训
MySQL grouping query
Type conversion, variable
1164 Good in C
鸿蒙第三次培训
随机推荐
Leetcode 669 pruning binary search tree -- recursive method and iterative method
How to enforce parameters in PowerShell- How do I make parameters mandatory in PowerShell?
Talk about the design and implementation logic of payment process
Is AI too slow to design pictures and draw illustrations? 3 sets of practical brushes to save you
STM32 realizes 74HC595 control
【RT-Thread】nxp rt10xx 设备驱动框架之--Audio搭建和使用
kubernetes资源对象介绍及常用命令(三)
远程办公工具分享|社区征文
How to train mask r-cnn model with your own data
Collection of the most beautiful graduation photos in the graduation season, collection of excellent graduation photos
kubernetes资源对象介绍及常用命令(四)
What is the difference between cloud server and cloud virtual machine
Discussion sur la logique de conception et de mise en oeuvre du processus de paiement
[combinatorics] recursive equation (example of solving recursive equation without multiple roots | complete process of solving recursive equation without multiple roots)
Kubernetes resource object introduction and common commands (V) - (NFS & PV & PVC)
How to purchase Google colab members in China
TCP拥塞控制详解 | 3. 设计空间
Luogu: p1155 [noip2008 improvement group] double stack sorting (bipartite graph, simulation)
List of financial products in 2022
AcWing 4489. Longest subsequence