Tệp tải xuống của Laravel từ S3

S3 của Amazon là một giải pháp tuyệt vời để lưu trữ tệp và Laravel làm cho nó dễ sử dụng. Đôi khi, bạn sẽ cần buộc các tệp tải xuống thay vì chỉ hiển thị tệp đó trong trình duyệt, nhưng rất may điều này cũng dễ dàng. Thay vì lãng phí tài nguyên máy chủ của bạn để truyền phát tệp từ S3 tới người dùng của bạn, chúng tôi sẽ sử dụng các URL đã ký

Các URL đã ký có thể cấp cho người dùng quyền truy cập tạm thời vào một tệp cụ thể trong vùng lưu trữ riêng tư của bạn, vì vậy, chúng tôi chỉ cần chuyển hướng đến đó và yêu cầu S3 đặt tiêu đề bổ sung. Trong bộ điều khiển của bạn chịu trách nhiệm tải xuống các tệp, bạn chỉ cần trả lại phản hồi như bên dưới

return redirect(Storage::disk('s3')->temporaryUrl(
    $file->path,
    now()->hour(),
    ['ResponseContentDisposition' => 'attachment']
));

Trong ví dụ này, $file->path là đường dẫn tệp của tôi trong bộ chứa S3 của tôi và now()->addHour() đang tạo dấu thời gian Carbon một giờ trong tương lai khi URL đã ký của chúng tôi sẽ hết hạn. Phần quan trọng là tùy chọn ['ResponseContentDisposition' => 'attachment'] cho S3 biết người dùng của chúng tôi muốn tải xuống tệp thay vì hiển thị tệp trong trình duyệt

Trong chương này, chúng tôi sẽ triển khai khả năng tải xuống và tải lên các tệp trong ứng dụng. Ngoài ra, chúng tôi sẽ thảo luận về một số khía cạnh khi làm việc với các tệp trong Kubernetes và cung cấp một ví dụ thực tế về việc sử dụng bộ lưu trữ tương thích với S3

Ứng dụng được mô tả trong chương này không nhằm mục đích sử dụng trong môi trường sản xuất nguyên trạng. Lưu ý rằng cần hoàn thành thành công toàn bộ hướng dẫn này để tạo ứng dụng sẵn sàng sản xuất

Chuẩn bị môi trường

Nếu bạn chưa chuẩn bị môi trường của mình trong các bước trước, vui lòng thực hiện theo hướng dẫn được cung cấp trong chương “Chuẩn bị môi trường”

Nếu môi trường của bạn ngừng hoạt động hoặc các hướng dẫn trong chương này không hoạt động, vui lòng tham khảo các gợi ý này

Docker có đang chạy không?

Hệ điều hành Linux MacOS Windows

Hãy khởi chạy Docker Desktop. Phải mất một thời gian để ứng dụng này khởi động Docker. Nếu không có lỗi trong quá trình khởi động, hãy kiểm tra xem Docker có đang chạy và được cấu hình đúng không

docker run hello-world

Bạn sẽ thấy đầu ra sau nếu lệnh hoàn thành thành công

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:9f6ad537c5132bcce57f7a0a20e317228d382c3cd61edae14650eec68b2b345c
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

Nếu bạn gặp bất kỳ vấn đề nào, vui lòng tham khảo tài liệu về Docker

Hãy khởi chạy ứng dụng Docker Desktop. Phải mất một thời gian để ứng dụng khởi động Docker. Nếu không có lỗi trong quá trình khởi động, thì hãy kiểm tra xem Docker có đang chạy và được cấu hình đúng không

docker run hello-world

Bạn sẽ thấy đầu ra sau nếu lệnh hoàn thành thành công

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:9f6ad537c5132bcce57f7a0a20e317228d382c3cd61edae14650eec68b2b345c
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

Nếu bạn gặp bất kỳ vấn đề nào, vui lòng tham khảo tài liệu về Docker

Bắt đầu docker

sudo systemctl restart docker

Đảm bảo rằng Docker đang chạy

sudo systemctl status docker

Nếu khởi động Docker thành công, bạn sẽ thấy đầu ra sau

● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2021-06-24 13:05:17 MSK; 13s ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 2013888 (dockerd)
      Tasks: 36
     Memory: 100.3M
     CGroup: /system.slice/docker.service
             └─2013888 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

dockerd[2013888]: time="2021-06-24T13:05:16.936197880+03:00" level=warning msg="Your kernel does not support CPU realtime scheduler"
dockerd[2013888]: time="2021-06-24T13:05:16.936219851+03:00" level=warning msg="Your kernel does not support cgroup blkio weight"
dockerd[2013888]: time="2021-06-24T13:05:16.936224976+03:00" level=warning msg="Your kernel does not support cgroup blkio weight_device"
dockerd[2013888]: time="2021-06-24T13:05:16.936311001+03:00" level=info msg="Loading containers: start."
dockerd[2013888]: time="2021-06-24T13:05:17.119938367+03:00" level=info msg="Loading containers: done."
dockerd[2013888]: time="2021-06-24T13:05:17.134054120+03:00" level=info msg="Daemon has completed initialization"
systemd[1]: Started Docker Application Container Engine.
dockerd[2013888]: time="2021-06-24T13:05:17.148493957+03:00" level=info msg="API listen on /run/docker.sock"

Bây giờ hãy kiểm tra xem Docker có sẵn không và cấu hình của nó đã chính xác chưa

docker run hello-world

Bạn sẽ thấy đầu ra sau nếu lệnh hoàn thành thành công

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:9f6ad537c5132bcce57f7a0a20e317228d382c3cd61edae14650eec68b2b345c
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

Nếu bạn có bất kỳ vấn đề, xin vui lòng tham khảo các

Bạn đã khởi động lại máy tính sau khi thiết lập môi trường chưa?

Hệ điều hành Linux / macOS

Hãy bắt đầu cụm minikube mà chúng ta đã cấu hình trong chương “Chuẩn bị môi trường”

minikube start

Đặt Không gian tên mặc định để bạn không phải chỉ định nó mỗi khi bạn gọi

sudo systemctl restart docker
6

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:9f6ad537c5132bcce57f7a0a20e317228d382c3cd61edae14650eec68b2b345c
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.
0

Bạn sẽ thấy đầu ra sau nếu lệnh hoàn thành thành công

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:9f6ad537c5132bcce57f7a0a20e317228d382c3cd61edae14650eec68b2b345c
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.
1

Đảm bảo rằng đầu ra lệnh chứa dòng sau

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:9f6ad537c5132bcce57f7a0a20e317228d382c3cd61edae14650eec68b2b345c
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.
2

Sự vắng mặt của nó có nghĩa là một cụm minikube mới đã được tạo thay vì sử dụng cụm cũ. Trong trường hợp này, hãy lặp lại tất cả các bước cần thiết để cài đặt môi trường sử dụng minikube

Bây giờ hãy chạy lệnh trong thiết bị đầu cuối PowerShell nền (không đóng cửa sổ của nó)

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:9f6ad537c5132bcce57f7a0a20e317228d382c3cd61edae14650eec68b2b345c
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.
3

Hãy bắt đầu cụm minikube mà chúng ta đã cấu hình trong chương “Chuẩn bị môi trường”

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:9f6ad537c5132bcce57f7a0a20e317228d382c3cd61edae14650eec68b2b345c
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.
4

Đặt Không gian tên mặc định để bạn không phải chỉ định nó mỗi khi bạn gọi

sudo systemctl restart docker
6

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:9f6ad537c5132bcce57f7a0a20e317228d382c3cd61edae14650eec68b2b345c
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.
5

Bạn sẽ thấy đầu ra sau nếu lệnh hoàn thành thành công

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:9f6ad537c5132bcce57f7a0a20e317228d382c3cd61edae14650eec68b2b345c
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.
1

Đảm bảo rằng đầu ra lệnh chứa dòng sau

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:9f6ad537c5132bcce57f7a0a20e317228d382c3cd61edae14650eec68b2b345c
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.
2

Sự vắng mặt của nó có nghĩa là một cụm minikube mới đã được tạo thay vì sử dụng cụm cũ. Trong trường hợp này, hãy lặp lại tất cả các bước cần thiết để cài đặt môi trường từ đầu bằng minikube

Bạn đã vô tình xóa Không gian tên của ứng dụng?

Nếu lỡ tay xóa Namespace của ứng dụng, bạn phải chạy lệnh sau để thực hiện theo hướng dẫn

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:9f6ad537c5132bcce57f7a0a20e317228d382c3cd61edae14650eec68b2b345c
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.
8

Bạn sẽ thấy đầu ra sau nếu lệnh hoàn thành thành công

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:9f6ad537c5132bcce57f7a0a20e317228d382c3cd61edae14650eec68b2b345c
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.
9

Không có gì giúp được;

Nếu không có gì hiệu quả, hãy lặp lại tất cả các bước được mô tả trong chương "Chuẩn bị môi trường" và tạo một môi trường mới từ đầu. Nếu việc tạo môi trường từ đầu cũng không giúp được gì, vui lòng cho chúng tôi biết về sự cố của bạn trong cuộc trò chuyện Telegram của chúng tôi hoặc tạo sự cố trên GitHub. Chúng tôi sẽ rất vui khi được giúp bạn

Chuẩn bị kho lưu trữ

Tôi đang làm theo hướng dẫn từ đầu Tôi mới bắt đầu từ chương này

Cập nhật kho lưu trữ hiện có chứa ứng dụng

Hệ điều hành Linux / macOS

Chạy các lệnh sau trong PowerShell

docker run hello-world
0

Chúng tôi sẽ thực hiện những thay đổi nào

docker run hello-world
1

Chạy các lệnh sau trong Bash

docker run hello-world
2

Chúng tôi sẽ thực hiện những thay đổi nào

docker run hello-world
3

Không hoạt động?

Chuẩn bị một kho lưu trữ mới với ứng dụng

Hệ điều hành Linux / macOS

Chạy các lệnh sau trong PowerShell

docker run hello-world
4

Chúng tôi sẽ thực hiện những thay đổi nào

docker run hello-world
1

Chạy các lệnh sau trong Bash

docker run hello-world
6

Chúng tôi sẽ thực hiện những thay đổi nào

docker run hello-world
3

Lưu trữ tệp

Các thùng chứa đang chạy trong Kubernetes thường được tạo và xóa tự động, e. g. , do các bản cập nhật Triển khai. Điều này có nghĩa là các tệp ứng dụng không thể được lưu trữ trên hệ thống tệp vùng chứa vì các tệp đó sẽ được

  • có sẵn cho một bản sao vùng chứa/ứng dụng thay vì tất cả chúng;
  • bị xóa khi container bị giết

Do đó, thật hợp lý khi chỉ lưu trữ trong các vùng chứa dữ liệu mà bạn có thể đủ khả năng để mất

Nhân tiện, bạn có thể đặt hệ thống tệp vùng chứa thành chỉ đọc. Điều này sẽ cải thiện bảo mật và ngăn ứng dụng lưu trữ dữ liệu cục bộ

Nhưng nếu bạn cần giữ một số dữ liệu thì sao? . Ví dụ: cơ sở dữ liệu NoSQL như kho lưu trữ đối tượng thường được sử dụng để lưu trữ các tệp thông thường. Cửa hàng đối tượng cung cấp API tương thích với Amazon S3 đặc biệt phổ biến

Dưới đây, chúng tôi sẽ chỉ cho bạn cách lưu trữ tệp trong bộ lưu trữ tương thích với S3 thay vì hệ thống tệp cục bộ. Bằng cách này, ứng dụng của bạn có thể duy trì trạng thái không trạng thái và tránh được một số sự cố khi làm việc trong Kubernetes

cài đặt phụ thuộc

Hãy cài đặt phần phụ thuộc còn thiếu bằng cách sử dụng vùng chứa

sudo systemctl restart docker
8

docker run hello-world
8

Chúng tôi đã chuyển bố cục hệ thống tệp Laravel từ kho lưu trữ chính thức. Những thay đổi sau đây đã được thực hiện cho ứng dụng của chúng tôi

  1. Tạo cấu hình/hệ thống tập tin. tập tin cấu hình php

Thêm các điểm cuối sudo systemctl restart docker 9 và sudo systemctl status docker 0 vào ứng dụng

Hãy thêm hai điểm cuối mới,

sudo systemctl restart docker
9 (để tải tệp lên bộ lưu trữ đối tượng tương thích với S3) và
sudo systemctl status docker
0 (để tải xuống tệp từ bộ lưu trữ đối tượng tương thích với S3), để xem cách tải lên và tải xuống hoạt động

Hãy thêm một bộ điều khiển mới

ứng dụng/Http/Bộ điều khiển/S3FileController. php Sao chép tên tệp Sao chép văn bản

docker run hello-world
9

missing($this->fileName)) { return "You haven't uploaded anything yet."; } return Storage::disk('s3')->download($this->fileName); } public function upload(Request $request): string { if (!$request->hasFile('file')) { return "You didn't pass the file to upload :("; } Storage::disk('s3')->putFileAs( '', $request->file('file'), $this->fileName ); return "File uploaded."; } }

Bây giờ là lúc để thêm các đường dẫn mới vào các tuyến đường

tuyến đường/web. php Sao chép tên tệp Sao chép văn bản

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:9f6ad537c5132bcce57f7a0a20e317228d382c3cd61edae14650eec68b2b345c
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.
0

Tuyến đường. get('/download', [S3FileController. lớp, 'tải xuống']); . bài đăng ('/ tải lên', [S3FileController. lớp, 'tải lên']);

Điểm cuối mới,

sudo systemctl restart docker
9 và
sudo systemctl status docker
0, đã được thêm vào. Tiếp theo, chúng ta cần cấu hình chúng để hoạt động với bộ lưu trữ

Triển khai và cấu hình MinIO

Với mục đích minh họa, chúng tôi sẽ sử dụng bộ lưu trữ đối tượng tương thích với MinIO S3. Tuy nhiên, bạn có thể sử dụng bất kỳ bộ lưu trữ tương thích với S3 nào khác (chẳng hạn như Amazon S3) để thay thế

Nếu sử dụng loại lưu trữ S3 khác, bạn không cần tạo MinIO’s StatefulSet và Job như mô tả bên dưới. Tuy nhiên, tất cả các bước tiếp theo vẫn không thay đổi

Hãy thêm một StatefulSet cho MinIO

lãnh đạo/mẫu/lưu trữ. yaml Sao chép tên tệp Sao chép văn bản

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:9f6ad537c5132bcce57f7a0a20e317228d382c3cd61edae14650eec68b2b345c
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.
1

phiên bản api. loại ứng dụng/v1. Siêu dữ liệu StatefulSet. Tên. thông số kỹ thuật nhỏ. Tên dịch vụ. bộ chọn nhỏ. trận đấuNhãn. ứng dụng. mẫu minio. metadata. nhãn. ứng dụng. thông số kỹ thuật nhỏ. hộp đựng. - Tên. hình ảnh nhỏ. minio/minio args. ["máy chủ", "/dữ liệu", "--console-address", ". 9001"] cổng. - cảng container. 9000 tên. minio - containerPort. 9001 tên. bảng điều khiển env. - Tên. Giá trị MINIO_ROOT_USER. quản trị viên nhỏ - tên. Giá trị MINIO_ROOT_PASSWORD. khối lượng minioadminMount. - Tên. mountPath dữ liệu nhỏ. / khối lượng dữ liệuClaimTemplates. - metadata. Tên. thông số dữ liệu nhỏ. chế độ truy cập. ["ReadWriteOnce"] tài nguyên. yêu cầu. kho. 100Mi --- apiVersion. loại v1. siêu dữ liệu dịch vụ. Tên. thông số kỹ thuật nhỏ. bộ chọn. ứng dụng. cổng mini. - Hải cảng. 9000 tên. minio - cảng. 9001 tên. bảng điều khiển

Bước tiếp theo là tạo một Công việc để thiết lập MinIO

helm/templates/job-setup-minio. yaml Sao chép tên tệp Sao chép văn bản

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:9f6ad537c5132bcce57f7a0a20e317228d382c3cd61edae14650eec68b2b345c
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.
2

phiên bản api. lô/v1 loại. siêu dữ liệu công việc. Tên. chú thích "thiết lập-minio". "tay lái. sh/móc". sau cài đặt, sau nâng cấp "lái. sh/trọng lượng móc". Mũ bảo hiểm "-1" ". sh/hook-xóa-chính sách". thông số kỹ thuật trước khi tạo hook. backoffGiới hạn. 0 mẫu. thông số kỹ thuật. khởi động lạichính sách. không bao giờ container. - Tên. hình ảnh thiết lập-minio. lệnh minio/mc. - sh - -euc -. is_minio_available() { try=$1 i=0 while [ $i -lt $tries ]; . // thu nhỏ. 9000/minio/sức khỏe/sống. return 1 i=$((i+1)) ngủ xong 1 } cho đến khi is_minio_available 10; . // thu nhỏ. 9000 minioadmin minioadmin mc mb --ignore-current minio/werf-guide-app

Thêm cấu hình để kết nối với MinIO

lãnh đạo/mẫu/triển khai. yaml Sao chép tên tệp Sao chép văn bản

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:9f6ad537c5132bcce57f7a0a20e317228d382c3cd61edae14650eec68b2b345c
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.
3

- Tên. Giá trị AWS_ENDPOINT. http. // thu nhỏ. 9000 - tên. Giá trị AWS_ACCESS_KEY_ID. quản trị viên nhỏ - tên. Giá trị AWS_SECRET_ACCESS_KEY. quản trị viên nhỏ - tên. Giá trị AWS_DEFAULT_REGION. chúng tôi-đông-1 - tên. Giá trị AWS_BUCKET. werf-guide-ứng dụng - tên. Giá trị AWS_USE_PATH_STYLE_ENDPOINT. "ĐÚNG VẬY"

MinIO hiện đã sẵn sàng để được triển khai trong khi ứng dụng của chúng tôi được định cấu hình để lưu trữ các tệp với nó

Thử nghiệm lưu trữ

Trước tiên, hãy triển khai ứng dụng của chúng tôi

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:9f6ad537c5132bcce57f7a0a20e317228d382c3cd61edae14650eec68b2b345c
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.
4

Bạn sẽ thấy đầu ra sau

hội tụ werf. log Sao chép tên tệp Sao chép văn bản

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:9f6ad537c5132bcce57f7a0a20e317228d382c3cd61edae14650eec68b2b345c
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.
5

.. ┌ ⛵ image backend │ ┌ Building stage backend/dockerfile │ │ backend/dockerfile Sending build context to Docker daemon 523.8kB │ │ backend/dockerfile Step 1/19 : FROM php:8.0-fpm-alpine as base │ │ backend/dockerfile ---> 52c511f481c5 .. │ │ backend/dockerfile Successfully built 827b4e8a1dbc │ │ backend/dockerfile Successfully tagged 84faa251-5b40-47ec-b3ff-15f5e74ca2c0:latest │ ├ Info │ │ name: /werf-guide-app:ec74eb832fd53166cee3165029dc1972ccfaca61f6c8c4c16764ff74-1634030394327 │ │ id: 827b4e8a1dbc │ │ created: 2022-10-12 12:19:54 +0000 UTC │ │ size: 58.9 MiB │ └ Building stage backend/dockerfile (31.12 seconds) └ ⛵ image backend (37.41 seconds) ┌ ⛵ image frontend │ ┌ Building stage frontend/dockerfile │ │ frontend/dockerfile Sending build context to Docker daemon 523.8kB │ │ frontend/dockerfile Step 1/30 : FROM php:8.0-fpm-alpine as base │ │ frontend/dockerfile ---> 52c511f481c5 .. │ │ frontend/dockerfile Successfully built b9edbffedeaa │ │ frontend/dockerfile Successfully tagged a0ef6fe8-6c05-47fe-9bcb-61ae41007bff:latest │ ├ Info │ │ name: /werf-guide-app:28b54c42d4db8dcdfe88212b67869b896dffb94a47590c5aa9916ef7-1634030450234 │ │ id: b9edbffedeaa │ │ created: 2022-10-12 12:20:50 +0000 UTC │ │ size: 9.4 MiB │ └ Building stage frontend/dockerfile (81.60 seconds) └ ⛵ image frontend (87.70 seconds) ┌ Waiting for release resources to become ready │ ┌ Status progress │ │ DEPLOYMENT REPLICAS AVAILABLE UP-TO-DATE │ │ werf-guide-app 2->1/1 1 1 │ │ │ POD READY RESTARTS STATUS │ │ ├── guide-app-5bb9488dd8-k7cf6 2/2 0 ContainerCreating -> │ │ │ Running │ │ └── guide-app-8848f446b-7hmkl 2/2 0 Running -> Terminating │ │ STATEFULSET REPLICAS READY UP-TO-DATE │ │ minio 1/1 1 1 │ │ mysql 1/1 1 1 ↵ │ │ │ └ Status progress └ Waiting for release resources to become ready (13.39 seconds) .. ┌ Waiting for helm hook job/setup-minio termination │ ┌ job/setup-minio po/setup-minio-xx2np container/setup-minio logs │ │ Added `minio` successfully. │ │ Bucket created successfully `minio/werf-guide-app`. │ └ job/setup-minio po/setup-minio-xx2np container/setup-minio logs │ │ ┌ Status progress │ │ JOB ACTIVE DURATION SUCCEEDED/FAILED │ │ setup-minio 0 13s 0->1/0 │ │ │ POD READY RESTARTS STATUS │ │ └── minio-xx2np 0/1 0 Running -> Completed │ └ Status progress └ Waiting for helm hook job/setup-minio termination (13.96 seconds) NAME: werf-guide-app LAST DEPLOYED: Tue Oct 12 12:21:07 2022 NAMESPACE: werf-guide-app STATUS: deployed REVISION: 18 TEST SUITE: None Running time 142.49 seconds

Bây giờ, hãy truy cập vào điểm cuối

sudo systemctl status docker
0 để lấy tệp từ S3

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:9f6ad537c5132bcce57f7a0a20e317228d382c3cd61edae14650eec68b2b345c
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.
6

Vì chúng tôi chưa tải lên bất kỳ tệp nào, chúng tôi sẽ nhận được tệp này

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:9f6ad537c5132bcce57f7a0a20e317228d382c3cd61edae14650eec68b2b345c
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.
7

Bây giờ, hãy tạo một tệp mới và tải nó lên bộ lưu trữ S3

Hệ điều hành Linux/macOS

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:9f6ad537c5132bcce57f7a0a20e317228d382c3cd61edae14650eec68b2b345c
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.
8

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:9f6ad537c5132bcce57f7a0a20e317228d382c3cd61edae14650eec68b2b345c
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.
9

Đầu ra dự kiến ​​cho biết tệp đã được thêm thành công vào bộ lưu trữ

sudo systemctl restart docker
0

Hãy thử lấy lại tệp từ bộ lưu trữ

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:9f6ad537c5132bcce57f7a0a20e317228d382c3cd61edae14650eec68b2b345c
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.
6

Bạn sẽ thấy nội dung tập tin

sudo systemctl restart docker
2

Hãy đảm bảo rằng tệp được lưu trực tiếp vào bộ lưu trữ và được lấy từ đó. Để thực hiện việc này, hãy chạy vùng chứa có công cụ

sudo systemctl status docker
6 để tương tác với MinIO

sudo systemctl restart docker
3

Bây giờ, hãy thực hiện các lệnh sau trong trình bao của vùng chứa

sudo systemctl restart docker
4

kết quả mong đợi

sudo systemctl restart docker
2

Trong chương này, chúng ta đã học cách lưu trữ tệp trong bộ lưu trữ đối tượng tương thích với S3 thay vì hệ thống tệp chứa. Với phương pháp này, các Pod ứng dụng có thể được tạo và xóa mà không gặp sự cố. các tệp được lưu trữ an toàn và bất kỳ bản sao ứng dụng nào cũng có thể nhanh chóng truy cập chúng. Đồng thời, hệ thống tệp trên các nút Kubernetes sẽ không chứa đầy các tệp không cần thiết

Hãy nhớ rằng bạn chỉ có thể lưu trữ dữ liệu mà bạn có thể mất trong vùng chứa. Tất cả các dữ liệu khác phải được lưu trữ trong cơ sở dữ liệu/lưu trữ thích hợp. Cách tiếp cận này được nhiều người ủng hộ, e. g. bạn có thể tìm thấy nó trong các kỹ sư của Google Cloud