שימוש ב-phpMyAdmin עם Cloud SQL ב-Cloud Run

במדריך הזה נסביר איך להתקין את phpMyAdmin ב-Cloud Run. אתם יכולים להשתמש ב-phpMyAdmin כדי לנהל את Cloud SQL באינטרנט.

המדריך הזה יעזור לכם אם אתם:

  • לארח אפליקציות ב-Cloud Run.
  • להשתמש ב-Cloud SQL כמסד הנתונים.
  • רוצים להשתמש ב-phpMyAdmin כממשק ל-MySQL או מעדיפים ממשק אינטרנט לניהול מסדי נתונים.

מטרות

  • איך פורסים את phpMyAdmin ב-Cloud Run.

עלויות

במדריך הזה משתמשים ברכיבים של Google Cloud, והשימוש בהם כרוך בתשלום, כולל:

כדי להעריך את העלויות בהתאם לשימוש הצפוי, אתם יכולים להיעזר במחשבון העלויות.

משתמשים חדשים ב-Cloud Platform עשויים להיות זכאים ל Google Cloud תקופת ניסיון בחינם.

לפני שמתחילים

  1. נכנסים לחשבון Google Cloud . אנחנו ממליצים למשתמשים חדשים ב- Google Cloud ליצור חשבון כדי שיוכלו להעריך את הביצועים של המוצרים שלנו בתרחישים מהעולם האמיתי. לקוחות חדשים מקבלים בחינם גם קרדיט בשווי 300$ להרצה, לבדיקה ולפריסה של עומסי העבודה.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. Install the gcloud CLI.

  5. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  6. To initialize the gcloud CLI, run the following command:

    gcloud init
  7. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  8. Verify that billing is enabled for your Google Cloud project.

  9. Install the gcloud CLI.

  10. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  11. To initialize the gcloud CLI, run the following command:

    gcloud init
  12. יוצרים מכונה של Cloud SQL מהדור השני עם כתובת IP פרטית.
  13. יוצרים משתמש במסד הנתונים.

יצירת שירות באמצעות קובץ האימג' של phpMyAdmin

המסוף

  1. נכנסים ל-Cloud Run במסוף Google Cloud :

    כניסה ל-Cloud Run

  2. לוחצים על יצירת שירות.

    1. בשדה של כתובת ה-URL של קובץ האימג' של הקונטיינר, מזינים את הערך phpmyadmin. ‫Cloud Run שולף את קובץ האימג' מ-Docker Hub הציבורי.
    2. בשדה Service name, מזינים phpmyadmin.
    3. בודקים את Require authentication.
    4. לוחצים על Container(s), volumes, networking, security כדי להגדיר את האפשרויות הבאות:
      1. בשדה Port, מזינים 80 בתור הערך של יציאת הקונטיינר.
      2. בקטע Environment variables, מוסיפים את PMA_HOST ומגדירים את הערך לכתובת ה-IP הפנימית של המכונה ב-Cloud SQL.
    5. בקטע Networking, בוחרים באפשרויות Connect to a VPC for outbound traffic ו-Send traffic directly to a VPC. בוחרים את אותה רשת כמו של המכונה של Cloud SQL.

התחברות לשירות באמצעות שרת proxy של Cloud Run

כדי לגשת בצורה מאובטחת לשירות שמוגן באמצעות IAM, צריך להשתמש בשרת proxy למפתחים של Cloud Run.

  1. כדי להפעיל את שרת ה-proxy בשירות שיצרתם, משתמשים בפקודה הבאה:

    gcloud run services proxy phpmyadmin --port=8080
    

    אם ב-CLI של gcloud מוצגת בקשה להתקין את הרכיבים של cloud-run-proxy, מזינים Y.

  2. כדי לבדוק את ההגדרה, מזינים את כתובת ה-URL ומספר היציאה (לדוגמה, http://127.0.0.1:8080/), ואז את שם המשתמש (שם האדמין) והסיסמה. מכיוון שאתם משתמשים בשרת ה-proxy המקומי של Cloud Run למפתחים כדי לגשת לשירות באופן מאובטח, יכול להיות שתופיע הודעת השגיאה הבאה, שאפשר להתעלם ממנה: There is a mismatch between HTTPS indicated on the server and client.

פתרון בעיות

כדי לקבל מידע על שגיאות ב-Cloud Run, נכנסים ליומני Cloud Run במסוףGoogle Cloud .

הסרת המשאבים

אחרי שמסיימים את המדריך, אפשר למחוק את המשאבים שנוצרו, כדי שהם יפסיקו להשתמש במכסה ולצבור חיובים. בסעיפים הבאים מוסבר איך למחוק או להשבית את המשאבים האלו.

מחיקת הפרויקט

הדרך הקלה ביותר לבטל את החיוב היא למחוק את הפרויקט שיצרתם בשביל המדריך הזה.

כדי למחוק את הפרויקט:

  1. במסוף Google Cloud , נכנסים לדף Manage resources.

    כניסה לדף Manage resources

  2. ברשימת הפרויקטים, בוחרים את הפרויקט שרוצים למחוק ולוחצים על Delete.
  3. כדי למחוק את הפרויקט, כותבים את מזהה הפרויקט בתיבת הדו-שיח ולוחצים על Shut down.

מחיקת מכונות

כדי למחוק מכונה של Cloud SQL:

  1. נכנסים לדף Instances במסוף Google Cloud .

    כניסה לדף Instances

  2. לוחצים על השם של מכונת ה-SQL שרוצים למחוק.
  3. כדי למחוק את המכונה, לוחצים על Delete ופועלים לפי ההוראות.

המאמרים הבאים