0Pricing
Docker & Kubernetes for Developers · درس

نشر Pod الأول

تعلّموا تعريف تطبيق بسيط ونشره بوصفه Pod في مجموعة Kubernetes باستخدام ملفات YAML و`kubectl`.

نشر Pod الأول درس مجاني في Docker & Kubernetes for Developers على CoddyKit. هذا هو الدرس 3 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Docker & Kubernetes for Developers، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Docker & Kubernetes for Developers 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

Pods: Smallest K8s Unit

In Kubernetes, the smallest deployable unit is a Pod. Think of a Pod as a logical host for one or more containers.

While Docker deals with individual containers, Kubernetes orchestrates Pods. A Pod encapsulates application containers, storage resources, a unique network IP, and options that govern how containers run.

Why Pods, Not Just Containers?

Why do we need Pods when we already have containers?

  • Shared Resources: Containers within the same Pod share the same network namespace and IP address. They can communicate using localhost.
  • Co-location: Pods ensure that co-located containers (like an app and a helper 'sidecar') are always scheduled together on the same node.
  • Abstraction: Pods provide an abstraction layer over individual containers, making orchestration simpler.

Anatomy of a Pod

A Pod is more than just a container. It includes:

  • Application Containers: One or more containers (e.g., your app, a logging agent).
  • Storage: Shared storage volumes for data persistence.
  • Network: A unique IP address and network namespace.
  • Configuration: Information on how to run the containers.

Pods are designed to be ephemeral. If a Pod dies, Kubernetes creates a new one (often managed by a higher-level object).

Defining Pods with YAML

Kubernetes resources, including Pods, are defined using YAML (YAML Ain't Markup Language) files. YAML is a human-readable data serialization standard.

These files act as blueprints, telling Kubernetes what you want to create and how.

Every Kubernetes object needs these top-level fields: apiVersion, kind, metadata, and spec.

Basic Pod YAML Structure

Let's look at the basic structure of a Pod definition in YAML:

apiVersion: v1
kind: Pod
metadata:
  name: my-first-pod
  labels:
    app: webserver
spec:
  containers:
    - name: my-container
      image: nginx:latest
      ports:
        - containerPort: 80

Our First Pod: Nginx

We'll deploy a simple Nginx web server as our first Pod. Nginx is a popular open-source HTTP server.

This manifest describes a Pod named nginx-pod, running a single container based on the nginx:latest Docker image, exposing port 80.

apiVersion: v1
kind: Pod
metadata:
  name: nginx-pod
  labels:
    app: nginx
spec:
  containers:
    - name: nginx-container
      image: nginx:latest
      ports:
        - containerPort: 80

Introducing `kubectl`

To interact with your Kubernetes cluster, you'll use the command-line tool called kubectl (pronounced "kube-control" or "kube-cuddle").

kubectl allows you to run commands against Kubernetes clusters, including deploying applications, inspecting and managing cluster resources, and viewing logs.

Ensure your kubectl is configured to point to your cluster.

Deploying Your Pod

Once you have your Pod definition in a YAML file (e.g., nginx-pod.yaml), you can deploy it to your Kubernetes cluster using the kubectl apply command.

This command tells Kubernetes to create or update resources based on the provided configuration.

Try running this:

kubectl apply -f nginx-pod.yaml

Checking Pod Status

After deploying, you'll want to check if your Pod is running correctly. Use kubectl get pods to see a list of all Pods in the current namespace.

To get more detailed information about a specific Pod, use kubectl describe pod <pod-name>.

  • Pending: Pod accepted, but containers not yet created.
  • Running: Pod has been bound to a node and all containers have been created.
  • Error: At least one container terminated in failure.
kubectl get pods
kubectl describe pod nginx-pod

Accessing Pod Logs

When debugging applications inside your Pod, checking the container logs is crucial. Use the kubectl logs command to retrieve logs from a container within a Pod.

This helps you see what your application is doing or if any errors occurred during startup or runtime.

kubectl logs nginx-pod

Pod Deployment Question

You've just learned how to define and deploy a Pod using YAML and kubectl. Imagine you've created my-app.yaml and deployed it.

Which command would you use to check the detailed status and events of your newly deployed Pod named my-app-pod?

Recap: Your First Pod

Congratulations! You've deployed your first Kubernetes Pod.

  • Pods are the smallest deployable units in Kubernetes, encapsulating containers, storage, and network.
  • You define Pods using YAML manifests with fields like apiVersion, kind, metadata, and spec.
  • The kubectl command-line tool is used to manage Kubernetes resources.
  • You deploy Pods with kubectl apply -f <filename>, check status with kubectl get pods and kubectl describe pod, and view logs with kubectl logs.

Next, we'll explore how Deployments manage Pods at scale!

الأسئلة الشائعة

هل درس «نشر Pod الأول» مجاني؟

نعم — نص درس «نشر Pod الأول» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Docker & Kubernetes for Developers، انتقل إلى CoddyKit PRO. تتضمن دورة Docker & Kubernetes for Developers 4 دروس في المجموع.

ماذا ستتعلم في «نشر Pod الأول»؟

تعلّموا تعريف تطبيق بسيط ونشره بوصفه Pod في مجموعة Kubernetes باستخدام ملفات YAML و`kubectl`. تتمرن على Docker & Kubernetes for Developers مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Docker & Kubernetes for Developers؟

لا تُشترط خبرة سابقة. Docker & Kubernetes for Developers على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 3 من أصل 4.

كم من الوقت يستغرق درس «نشر Pod الأول»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Docker & Kubernetes for Developers هذا؟

نعم. كل درس في Docker & Kubernetes for Developers يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. مقدمة إلى Kubernetes وأهميته
  2. بنية Kubernetes ومكوّناته
  3. نشر Pod الأول
  4. العمل باستخدام kubectl: أداة التحكم في عنقودك
← العودة إلى Docker & Kubernetes for Developers