יצירת אפליקציה עם תלות בהגדרות

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

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

  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. Enable the Google Kubernetes Engine API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

  5. 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

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

  7. Enable the Google Kubernetes Engine API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

  8. מתקינים את Git. כדי להעתיק דוגמאות למחשב, צריך להתקין את Git.
  9. אם עוד לא עשיתם זאת, מתקינים את הפלאגין Cloud Code.

יצירת אפליקציה

  1. משכפלים את מאגר Bank of Anthos:

    1. בסרגל התפריטים העליון, לוחצים על Terminal (טרמינל) > New Terminal (טרמינל חדש).
    2. משכפלים את מאגר Bank of Anthos:

      git clone https://github.com/GoogleCloudPlatform/bank-of-anthos.git
      
  2. כדי לפתוח את סביבת העבודה על סמך Bank of Anthos, ב-VS Code, לוחצים על File (קובץ) > Open folder (פתיחת תיקייה) ועוברים לתיקייה שבה בוצע שיבוט המאגר.

  3. לוחצים לחיצה כפולה על הקובץ skaffold.yaml.

    1. הקובץ מכיל כמה הגדרות, שמופרדות באמצעות מפרידי מסמכי YAML‏ (---). אפשר לפרוס כל הגדרה בנפרד או להפנות אליה כאל תלות.

      ---
      apiVersion: skaffold/v2beta18
      kind: Config
      
    2. הגדרות עם שם שצוין נקראות מודולי Skaffold. הקטע הבא מגדיר את המודול frontend.

      metadata:
      name: frontend # module defining frontend service
      
    3. יחסי תלות בין הגדרות מצוינים באמצעות התג configs. צריך לפרוס את ההגדרות הנדרשות לפני ההגדרה הנוכחית. בדוגמה מוצגת תלות שמוגדרת באותו קובץ. תג configs יכול גם להפנות לקבצים אחרים של skaffold.yaml בפרויקט הנוכחי.

      requires:
      - configs: [db]
      

פריסת מודולים

  1. פותחים את חלונית הפקודות (Ctrl/Cmd+Shift+P) ומריצים את הפקודה Cloud Code: Run on Kubernetes.
  2. לוחצים על בחירת מודולים.
  3. בוחרים את המודולים שרוצים לפרוס ולוחצים על אישור.

    אם לוחצים על db, נוצרות ההגדרות של db וההגדרות של setup שנדרשות.

  4. כשמופיעה בקשה, בוחרים מאגר תמונות ולוחצים על Enter.

סידור וארגון

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

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

אם אתם משתמשים ב- Google Cloud ורוצים למחוק רק את האשכול שלכם, אתם יכולים לעשות זאת באופן הבא:

  1. לוחצים על Cloud Code ומרחיבים את הסייר Kubernetes.
  2. מעבירים את מצביע העכבר מעל שם האשכול ולוחצים על open_in_new ואז על Open in Google Cloud console (פתיחה במסוף).
  3. לוחצים על מחיקה ואז על מחיקה.

כדי למחוק את הפרויקט (ואת המשאבים שמשויכים אליו, כולל אשכולות):

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

    כניסה לדף Projects

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

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

    הפעולה הזו משביתה את הפרויקט ומתזמנת את המחיקה שלו.

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