github.com/qsunny/k8s@v0.0.0-20220101153623-e6dca256d5bf/examples-master/staging/simple-nginx.md (about)

     1  ## Running your first containers in Kubernetes
     2  
     3  Ok, you've run one of the [getting started guides](https://kubernetes.io/docs/user-journeys/users/application-developer/foundational/#section-1) and you have
     4  successfully turned up a Kubernetes cluster.  Now what?  This guide will help you get oriented
     5  to Kubernetes and running your first containers on the cluster.
     6  
     7  ### Running a container (simple version)
     8  
     9  From this point onwards, it is assumed that `kubectl` is on your path from one of the getting started guides.
    10  
    11  The [`kubectl create`](https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#create) line below will create a [deployment](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/) named `my-nginx` to ensure that there are always a [nginx](https://hub.docker.com/_/nginx/) [pod](https://kubernetes.io/docs/concepts/workloads/pods/pod-overview/) running.
    12  
    13  ```bash
    14  kubectl create deployment --image nginx my-nginx
    15  ```
    16  
    17  You can list the pods to see what is up and running:
    18  
    19  ```bash
    20  kubectl get pods
    21  ```
    22  
    23  You can also see the deployment that was created:
    24  
    25  ```bash
    26  kubectl get deployment
    27  ```
    28  
    29  You can also scale the deployment to ensure there is two nginx pods running:
    30  
    31  ```bash
    32  kubectl scale deployment --replicas 2 my-nginx
    33  ```
    34  
    35  You can now list the pods to see there is two up and running:
    36  
    37  ```bash
    38  kubectl get pods
    39  ```
    40  
    41  ### Exposing your pods to the internet
    42  
    43  On some platforms (for example Google Compute Engine) the kubectl command can integrate with your cloud provider to add a [public IP address](https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services---service-types) for the pods,
    44  to do this run:
    45  
    46  ```bash
    47  kubectl expose deployment my-nginx --port=80 --type=LoadBalancer
    48  ```
    49  
    50  This should print the service that has been created, and map an external IP address to the service. Where to find this external IP address will depend on the environment you run in.  For instance, for Google Compute Engine the external IP address is listed as part of the newly created service and can be retrieved by running
    51  
    52  ```bash
    53  kubectl get services
    54  ```
    55  
    56  In order to access your nginx landing page, you also have to make sure that traffic from external IPs is allowed. Do this by opening a firewall to allow traffic on port 80.
    57  
    58  ### Cleanup
    59  
    60  To delete the two replicated containers, delete the deployment:
    61  
    62  ```bash
    63  kubectl delete deployment my-nginx
    64  ```
    65  
    66  ### Next: Configuration files
    67  
    68  Most people will eventually want to use declarative configuration files for creating/modifying their applications.  A [simplified introduction](https://kubernetes.io/docs/user-journeys/users/application-developer/foundational/#section-2)
    69  is given in a different document.
    70  
    71  
    72  <!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
    73  [![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/examples/simple-nginx.md?pixel)]()
    74  <!-- END MUNGE: GENERATED_ANALYTICS -->