在kubernetes中部署完整的Node js应用程序

First, you need to have Docker installed on your computer so that it will make this process easy for you. Docker and Kubernetes are two different things but you need Docker as a container runtime for your containers inside Kubernetes pods.

首先,您需要在您的计算机上安装Docker ,这样它才能使您轻松完成此过程。 Docker和Kubernetes是两个不同的东西,但是您需要将Docker作为Kubernetes容器内容器的容器运行时。

Download Docker Desktop to your computer using the link below. Then install it and make sure you get the output by running docker version on your terminal.

使用下面的链接将Docker Desktop下载到您的计算机。 然后安装它,并确保通过在终端上运行docker version获得输出。

创建一个Node.js应用程序 (Create a Node.js Application)

You can create your Node.js app according to your preferences, and if you’ve already created node app, you can use it for this tutorial. I’ll put my node app down below, so you can get an idea about the node application.

您可以根据自己的喜好创建Node.js应用,如果已经创建了Node应用,则可以在本教程中使用它。 我将节点应用程序放在下面,因此您可以对节点应用程序有所了解。

const express = require('express');


const app = express();


const port = 8080;


app.listen(port, () => {
    console.log('listening for request on port 8080');
});


app.get('/', (req, res) => {
    console.log('request made');
    res.sendFile("./docs/index.html", { root: __dirname })
});


app.get('/about', (req, res) => {
    res.sendFile('./docs/about.html', { root: __dirname });
});


app.get('/about-us', (req, res) => {
    res.redirect('/about');    
});


app.use((req, res) => {
    res.status(404).sendFile('./docs/404.html', { root: __dirname });
});

Here, you can see a simple node app created using express and I’ve set port 8080 for this application. Also, I’ve created docs folder inside the project and placed all my HTML files inside it. I’ve set basic routing to access different pages of my node app and I’ve added a 404 route at the bottom of the code to capture other requests.

在这里,您可以看到一个使用express创建的简单节点应用程序,并且为此应用程序设置了端口8080。 另外,我在项目内部创建了docs文件夹,并将所有HTML文件放入其中。 我已设置基本路由来访问节点应用程序的不同页面,并且在代码底部添加了404路由以捕获其他请求。

Image for post
Screens
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值