Running an Application in a Pod

Use the kubectl command to create a pod running an NGINX container in a Kubernetes cluster.

  1. Create a pod.

    To create a pod with a single running container, use the kubectl create command. For example, to create a pod with the nginx container image from the Oracle Container Registry:

    kubectl create deployment --image container-registry.oracle.com/olcne/nginx:1.17.7 hello-world

    This example uses hello-world as the name for the deployment. The pods are named by using the deployment name as a prefix.

    Tip:

    Deployment, pod, and service names conform to a requirement to match a DNS-1123 label. These must consist of lowercase alphanumeric characters or -, and must start and end with an alphanumeric character. The regular expression that's used to validate names is [a-z0-9]([-a-z0-9]*[a-z0-9])?. If you use a name for the deployment that doesn't validate, an error is returned.

    Many more optional parameters can be used when you run a new application within Kubernetes. For example, at run time, you can specify how many replica pods are to be started, or you might apply a label to the deployment to make it easier to identify pod components. To see a full list of options available to you, use the kubectl run --help command.

  2. List the pods.

    To check that a new application deployment has created one or more pods, use the kubectl get pods command:

    kubectl get pods

    The output looks similar to:

    NAME                           READY   STATUS    RESTARTS   AGE
    hello-world-5db76fbd7d-99s8h   1/1     Running   0          1m
  3. Show details about a pod.

    Use kubectl describe to show a more detailed view of pods, including which containers are running and what image they're based on, including which node is hosting the pod:

    kubectl describe pods

    The output looks similar to:

    Name:             hello-world-5db76fbd7d-99s8h
    Namespace:        default
    Priority:         0
    Service Account:  default
    Node:             <nodename>/<IP_address>
    Start Time:       <date> 11:08:37 +0000
    Labels:           app=hello-world
                      pod-template-hash=5db76fbd7d
    Annotations:      <none>
    Status:           Running
    IP:               10.244.1.26
    IPs:
      IP:           10.244.1.26
    Controlled By:  ReplicaSet/hello-world-5db76fbd7d
    Containers:
      nginx:
        Container ID:   cri-o://6f4ce80153cefbaea327dd011b035cfb2112eb31085ca358b9c894fa775...
        Image:          container-registry.oracle.com/olcne/nginx:1.17.7
        Image ID:       container-registry.oracle.com/olcne/nginx@sha256:78ce89068e7feb15ec...
        Port:           <none>
        Host Port:      <none>
        State:          Running
          Started:      <date> 11:08:43 +0000
        Ready:          True
        Restart Count:  0
        Environment:    <none>
        Mounts:
          /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-d9q4t (ro)
    Conditions:
      Type                        Status
      PodReadyToStartContainers   True 
      Initialized                 True 
      Ready                       True 
      ContainersReady             True 
      PodScheduled                True 
    Volumes:
      kube-api-access-d9q4t:
        Type:                    Projected (a volume that contains injected data 
                                                                from multiple sources)
        TokenExpirationSeconds:  3607
        ConfigMapName:           kube-root-ca.crt
        ConfigMapOptional:       <nil>
        DownwardAPI:             true
    QoS Class:                   BestEffort
    Node-Selectors:              <none>
    Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                                 node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
    Events:
    ...