use kubectl create deployment to create Deployment
This commit is contained in:
@@ -13,7 +13,7 @@ You can use the Kubernetes command line tool kubectl to interact with the API Se
|
|||||||
<!-- body -->
|
<!-- body -->
|
||||||
## docker run
|
## docker run
|
||||||
|
|
||||||
To run an nginx Pod and expose the Pod, see [kubectl run](/docs/reference/generated/kubectl/kubectl-commands/#run).
|
To run an nginx Deployment and expose the Deployment, see [kubectl create deployment](/docs/reference/generated/kubectl/kubectl-commands#-em-deployment-em-).
|
||||||
|
|
||||||
docker:
|
docker:
|
||||||
|
|
||||||
@@ -36,29 +36,35 @@ kubectl:
|
|||||||
|
|
||||||
```shell
|
```shell
|
||||||
# start the pod running nginx
|
# start the pod running nginx
|
||||||
kubectl run --image=nginx nginx-app --port=80 --env="DOMAIN=cluster"
|
kubectl create deployment --image=nginx nginx-app
|
||||||
```
|
```
|
||||||
```
|
```
|
||||||
pod/nginx-app created
|
deployment.apps/nginx-app created
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
# add env to nginx-app
|
||||||
|
kubectl set env deployment/nginx-app DOMAIN=cluster
|
||||||
|
```
|
||||||
|
```
|
||||||
|
deployment.apps/nginx-app env updated
|
||||||
```
|
```
|
||||||
|
|
||||||
{{< note >}}
|
{{< note >}}
|
||||||
Pods are considered to be relatively ephemeral (rather than durable) entities,so you should use Deployment instead to make sure that your container are available throughout the cluster,see [kubectl create deployment](/docs/reference/generated/kubectl/kubectl-commands/#-em-deployment-em-),or [assign this pod to Node](/docs/concepts/scheduling-eviction/assign-pod-node/#nodeselector).
|
`kubectl` commands print the type and name of the resource created or mutated, which can then be used in subsequent commands. You can expose a new Service after a Deployment is created.
|
||||||
{{< /note >}}
|
{{< /note >}}
|
||||||
|
|
||||||
You can expose a new Service after a Pod is created.
|
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
# expose a port through with a service
|
# expose a port through with a service
|
||||||
kubectl expose pod nginx-app --port=80 --name=nginx-http
|
kubectl expose deployment nginx-app --port=80 --name=nginx-http
|
||||||
```
|
```
|
||||||
```
|
```
|
||||||
service "nginx-http" exposed
|
service "nginx-http" exposed
|
||||||
```
|
```
|
||||||
|
|
||||||
By using kubectl, you can create a [Pod](/docs/concepts/workloads/pods/pod/) that pod are running nginx. You can also create a [service](/docs/concepts/services-networking/service/) with a selector that matches the pod labels. For more information, see [Use a Service to Access an Application in a Cluster](/docs/tasks/access-application-cluster/service-access-application-cluster).
|
By using kubectl, you can create a [Deployment](/docs/concepts/workloads/controllers/deployment/) to ensure that N pods are running nginx, where N is the number of replicas stated in the spec and defaults to 1. You can also create a [service](/docs/concepts/services-networking/service/) with a selector that matches the pod labels. For more information, see [Use a Service to Access an Application in a Cluster](/docs/tasks/access-application-cluster/service-access-application-cluster).
|
||||||
|
|
||||||
By default images run in the background, similar to `docker run -d ...`. To run things in the foreground, use:
|
By default images run in the background, similar to `docker run -d ...`. To run things in the foreground, use [`kubectl run`](/docs/reference/generated/kubectl/kubectl-commands/#run) to create pod:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
kubectl run [-i] [--tty] --attach <name> --image=<image>
|
kubectl run [-i] [--tty] --attach <name> --image=<image>
|
||||||
@@ -67,8 +73,8 @@ kubectl run [-i] [--tty] --attach <name> --image=<image>
|
|||||||
Unlike `docker run ...`, if you specify `--attach`, then you attach `stdin`, `stdout` and `stderr`. You cannot control which streams are attached (`docker -a ...`).
|
Unlike `docker run ...`, if you specify `--attach`, then you attach `stdin`, `stdout` and `stderr`. You cannot control which streams are attached (`docker -a ...`).
|
||||||
To detach from the container, you can type the escape sequence Ctrl+P followed by Ctrl+Q.
|
To detach from the container, you can type the escape sequence Ctrl+P followed by Ctrl+Q.
|
||||||
|
|
||||||
Because the kubectl run command starts a Pod for the container, the Pod restarts if you terminate the attached process by using Ctrl+C, unlike `docker run -it`.
|
Because the kubectl run command starts a Deployment for the container, the Deployment restarts if you terminate the attached process by using Ctrl+C, unlike `docker run -it`.
|
||||||
To destroy the pod you need to run `kubectl delete pod <name>`.
|
To destroy the Deployment and its pods you need to run `kubectl delete deployment <name>`.
|
||||||
|
|
||||||
## docker ps
|
## docker ps
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user