当前位置:网站首页>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.0see deployment
kubectl get deploymentssee 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-nodesummary
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
边栏推荐
- MinGW compile boost library
- List of financial products in 2022
- A day's work list of an ordinary programmer
- 2021 ICPC regional competition (Shanghai) g.edge groups (tree DP)
- SQL injection database operation foundation
- Leetcode 538 converts binary search tree into cumulative tree -- recursive method and iterative method
- [combinatorics] recursive equation (the non-homogeneous part is an exponential function and the bottom is the characteristic root | example of finding a special solution)
- QT学习日记9——对话框
- 【RT-Thread】nxp rt10xx 设备驱动框架之--hwtimer搭建和使用
- Research on Swift
猜你喜欢

Internet hospital his management platform source code, online consultation, appointment registration smart hospital applet source code

Talk about the design and implementation logic of payment process

Cloud primordial weekly | CNCF released the 2021 cloud primordial development status report, which was released on istio 1.13

Design e-commerce spike

Embedded-c language-7

一入“远程”终不悔,几人欢喜几人愁。| 社区征文

MySQL grouping query

【RT-Thread】nxp rt10xx 设备驱动框架之--hwtimer搭建和使用

Records of long objects and long judgments in the stream of list
![[RT thread] NXP rt10xx device driver framework -- RTC construction and use](/img/19/91a9d84ba84f81ef125c33eb4007bc.png)
[RT thread] NXP rt10xx device driver framework -- RTC construction and use
随机推荐
Leetcode 669 pruning binary search tree -- recursive method and iterative method
Write a program to process a list container of string type. Find a special value in the container 9.27: and delete it if found. Rewrite the above procedure with deque container.
Web-ui automated testing - the most complete element positioning method
Golang unit test, mock test and benchmark test
Golang单元测试、Mock测试以及基准测试
c# .net 工具生态
When absolutely positioned, the element is horizontally and vertically centered
Automata and automatic line of non-standard design
[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
Open vsftpd port under iptables firewall
AcWing 4489. Longest subsequence
How to read the source code [debug and observe the source code]
问题随记 —— 在 edge 上看视频会绿屏
Simple use of unity pen XR grab
Draw some simple graphics with MFC
How to purchase Google colab members in China
SQL injection database operation foundation
Inheritance of ES6 class
Y is always discrete and can't understand, how to solve it? Answer: read it several times
IntelliJ 2021.3 short command line when running applications