Tips Deploy apps on Amazon EKS

hongson161

New member
[TIẾNG VIỆT]:
## Cách triển khai ứng dụng trên Amazon EKS

Amazon đàn hồi Kubernetes Service (EKS) là dịch vụ Kubernetes được quản lý giúp dễ dàng chạy các ứng dụng được chứa trên AWS.Với EKS, bạn có thể tận dụng khả năng mở rộng, độ tin cậy và bảo mật của Kubernetes mà không cần phải quản lý cơ sở hạ tầng cơ bản.

Bài viết này sẽ chỉ cho bạn cách triển khai một ứng dụng đơn giản trên EKS bằng AWS CLI.Chúng tôi sẽ sử dụng [Amazon EKS BẮT ĐẦU] (https://aws.amazon.com/eks/quickstart/) để tạo cụm EKS mới.

### Điều kiện tiên quyết

Để làm theo với hướng dẫn này, bạn sẽ cần những điều sau đây:

* Tài khoản AWS
* AWS CLI đã cài đặt và cấu hình
* [Kubectl] (Install Tools) CLI công cụ được cài đặt

### Tạo cụm EKS

Bước đầu tiên là tạo cụm EKS.Bạn có thể làm điều này bằng cách sử dụng AWS CLI hoặc Bảng điều khiển quản lý AWS.Đối với hướng dẫn này, chúng tôi sẽ sử dụng AWS CLI.

Để tạo một cụm, hãy chạy lệnh sau:

`` `
AWS EKS Creat Creat
`` `

Điều này sẽ tạo ra một cụm EKS mới ở khu vực US-East-1.Cụm sẽ được đặt tên là `my-eks cluster`.

### Cài đặt plugin EKS CLI

Bước tiếp theo là cài đặt plugin EKS CLI.Plugin này sẽ cho phép bạn tương tác với cụm EKS của mình từ dòng lệnh.

Để cài đặt plugin, hãy chạy lệnh sau:

`` `
plugin kubectl cài đặt eks
`` `

### Kết nối với cụm EKS của bạn

Bây giờ bạn đã tạo một cụm EKS, bạn cần kết nối với nó.Bạn có thể làm điều này bằng cách sử dụng lệnh sau:

`` `
KUBECTL CLUSTER-INFO
`` `

Lệnh này sẽ in ra các chi tiết kết nối cho cụm EKS của bạn.

### Triển khai ứng dụng của bạn

Bây giờ bạn được kết nối với cụm EKS của mình, bạn có thể triển khai ứng dụng của mình.Đối với hướng dẫn này, chúng tôi sẽ sử dụng ứng dụng [Node.js] (Node.js) đơn giản.

Bước đầu tiên là tạo một thư mục mới cho ứng dụng của bạn.

`` `
MKDIR My-app
cd my-app
`` `

Tiếp theo, tạo một tệp mới có tên là `index.js`.Tệp này sẽ chứa mã cho ứng dụng của bạn.

`` `
const express = yêu cầu ('express');

const app = express ();

app.get ('/', (req, res) => {
res.Send ('Hello World!');
});

app.listen (3000);
`` `

Bây giờ bạn đã tạo ứng dụng của mình, bạn cần xây dựng nó.Bạn có thể làm điều này bằng cách sử dụng lệnh sau:

`` `
Cài đặt NPM
NPM Run Build
`` `

Điều này sẽ xây dựng ứng dụng của bạn và tạo một thư mục mới gọi là `dist`.Thư mục `dist` chứa mã được biên dịch cho ứng dụng của bạn.

Bước tiếp theo là tạo tệp kê khai Kubernetes.Tệp này sẽ mô tả ứng dụng của bạn vào Kubernetes.

Tạo một tệp mới có tên là `triển khai.yaml`.Tệp này sẽ chứa mã sau:

`` `
Apiversion: Ứng dụng/V1
Loại: Triển khai
metadata:
Tên: My-app
Thông số:
Bản sao: 1
bộ chọn:
Matchlabels:
Ứng dụng: app của tôi
bản mẫu:
metadata:
Nhãn:
Ứng dụng: app của tôi
Thông số:
hộp đựng:
- Tên: My-app
Hình ảnh: My-App: Mới nhất
Cổng:
- ContainerPort: 3000
`` `

Tệp kê khai này tạo ra một triển khai mới gọi là `my-app`.Việc triển khai sẽ có một bản sao và sẽ sử dụng hình ảnh `my-app: mới nhất`.

Bây giờ bạn đã tạo tệp kê khai Kubernetes của mình, bạn có thể triển khai ứng dụng của mình cho EKS.Bạn có thể làm điều này bằng cách sử dụng lệnh sau:

`` `
kubectl Ứng dụng -f triển khai.yaml
`` `

Lệnh này sẽ triển khai ứng dụng của bạn cho EKS.

### Xác minh

[ENGLISH]:
## How to Deploy Apps on Amazon EKS

Amazon Elastic Kubernetes Service (EKS) is a managed Kubernetes service that makes it easy to run containerized applications on AWS. With EKS, you can take advantage of the scalability, reliability, and security of Kubernetes without having to manage the underlying infrastructure.

This article will show you how to deploy a simple application on EKS using the AWS CLI. We'll be using the [Amazon EKS Quick Start](https://aws.amazon.com/eks/quickstart/) to create a new EKS cluster.

### Prerequisites

To follow along with this tutorial, you will need the following:

* An AWS account
* The AWS CLI installed and configured
* The [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/) CLI tool installed

### Create an EKS cluster

The first step is to create an EKS cluster. You can do this using the AWS CLI or the AWS Management Console. For this tutorial, we'll use the AWS CLI.

To create a cluster, run the following command:

```
aws eks create-cluster --name my-eks-cluster --region us-east-1
```

This will create a new EKS cluster in the us-east-1 region. The cluster will be named `my-eks-cluster`.

### Install the EKS CLI plugin

The next step is to install the EKS CLI plugin. This plugin will allow you to interact with your EKS cluster from the command line.

To install the plugin, run the following command:

```
kubectl plugin install eks
```

### Connect to your EKS cluster

Now that you have created an EKS cluster, you need to connect to it. You can do this using the following command:

```
kubectl cluster-info
```

This command will print out the connection details for your EKS cluster.

### Deploy your application

Now that you are connected to your EKS cluster, you can deploy your application. For this tutorial, we'll be using a simple [Node.js](https://nodejs.org/) application.

The first step is to create a new directory for your application.

```
mkdir my-app
cd my-app
```

Next, create a new file called `index.js`. This file will contain the code for your application.

```
const express = require('express');

const app = express();

app.get('/', (req, res) => {
res.send('Hello World!');
});

app.listen(3000);
```

Now that you have created your application, you need to build it. You can do this using the following command:

```
npm install
npm run build
```

This will build your application and create a new directory called `dist`. The `dist` directory contains the compiled code for your application.

The next step is to create a Kubernetes manifest file. This file will describe your application to Kubernetes.

Create a new file called `deployment.yaml`. This file will contain the following code:

```
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 1
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app
image: my-app:latest
ports:
- containerPort: 3000
```

This manifest file creates a new deployment called `my-app`. The deployment will have one replica and will use the image `my-app:latest`.

Now that you have created your Kubernetes manifest file, you can deploy your application to EKS. You can do this using the following command:

```
kubectl apply -f deployment.yaml
```

This command will deploy your application to EKS.

### Verify
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top