Skip to content

Commit 92f9650

Browse files
committed
add examples on how to transition from docker-cli to kubectl
1 parent f5e6161 commit 92f9650

File tree

3 files changed

+258
-1
lines changed

3 files changed

+258
-1
lines changed

docs/user-guide/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ If you don't have much familiarity with Kubernetes, we recommend you read the fo
106106
* [Specifying commands and requesting capabilities](containers.md)
107107
* [Downward API: accessing system configuration from a pod](downward-api.md)
108108
* [Images and registries](images.md)
109+
* [Migrating from docker-cli to kubectl](docker-cli-to-kubectl.md)
109110

110111

111112
<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
Lines changed: 255 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,255 @@
1+
<!-- BEGIN MUNGE: UNVERSIONED_WARNING -->
2+
3+
<!-- BEGIN STRIP_FOR_RELEASE -->
4+
5+
![WARNING](http://kubernetes.io/img/warning.png)
6+
![WARNING](http://kubernetes.io/img/warning.png)
7+
![WARNING](http://kubernetes.io/img/warning.png)
8+
9+
<h1>PLEASE NOTE: This document applies to the HEAD of the source
10+
tree only. If you are using a released version of Kubernetes, you almost
11+
certainly want the docs that go with that version.</h1>
12+
13+
<strong>Documentation for specific releases can be found at
14+
[releases.k8s.io](http://releases.k8s.io).</strong>
15+
16+
![WARNING](http://kubernetes.io/img/warning.png)
17+
![WARNING](http://kubernetes.io/img/warning.png)
18+
![WARNING](http://kubernetes.io/img/warning.png)
19+
20+
<!-- END STRIP_FOR_RELEASE -->
21+
22+
<!-- END MUNGE: UNVERSIONED_WARNING -->
23+
# kubectl for docker users
24+
25+
In this doc, we introduce the kubernetes command line to for interacting with the api to docker-cli users. The tool, kubectl, is designed to be familiar to docker-cli users but there are a few necessary differences. Each section of this doc highlights a docker subcommand explains the kubectl equivalent.
26+
27+
**Table of Contents**
28+
<!-- BEGIN MUNGE: GENERATED_TOC -->
29+
- [kubectl for docker users](#kubectl-for-docker-users)
30+
- [docker run](#docker-run)
31+
- [docker ps](#docker-ps)
32+
- [docker exec](#docker-exec)
33+
- [docker logs](#docker-logs)
34+
- [docker stop and docker rm](#docker-stop-and-docker-rm)
35+
- [docker login](#docker-login)
36+
- [docker version](#docker-version)
37+
- [docker info](#docker-info)
38+
39+
<!-- END MUNGE: GENERATED_TOC -->
40+
41+
#### docker run
42+
43+
How do I run an nginx container and expose it to the world? Checkout [kubectl run](kubectl/kubectl_run.md).
44+
45+
With docker:
46+
```
47+
$ docker run -d --restart=always --name nginx-app -p 80:80 nginx
48+
a9ec34d9878748d2f33dc20cb25c714ff21da8d40558b45bfaec9955859075d0
49+
$ docker ps
50+
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
51+
a9ec34d98787 nginx "nginx -g 'daemon of 2 seconds ago Up 2 seconds 0.0.0.0:80->80/tcp, 443/tcp nginx-app
52+
```
53+
54+
With kubectl:
55+
```
56+
# start the pod running nginx
57+
$ kubectl run --image=nginx nginx-app
58+
CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS
59+
nginx-app nginx-app nginx run=nginx-app 1
60+
# expose a port through with a service
61+
$ kubectl expose rc nginx-app --port=80 --name=nginx-http
62+
NAME LABELS SELECTOR IP(S) PORT(S)
63+
nginx-http run=nginx-app run=nginx-app 80/TCP
64+
```
65+
66+
With kubectl, we create a [replication controller](replication-controller.md) which will make sure that N pods are running nginx (where in is the number of replicas stated in the spec, which defaults to 1). We also create a [service](services.md) with a selector that matches the replication controller's selector. See the [quick-start.md](quick-start.md) guide for more information.
67+
68+
#### docker ps
69+
70+
How do I list what is currently running? Checkout [kubectl get](kubectl/kubectl_get.md).
71+
72+
With docker:
73+
```
74+
$ docker ps
75+
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
76+
a9ec34d98787 nginx "nginx -g 'daemon of About an hour ago Up About an hour 0.0.0.0:80->80/tcp, 443/tcp nginx-app
77+
```
78+
79+
With kubectl:
80+
```
81+
$ kubectl get po
82+
NAME READY STATUS RESTARTS AGE
83+
nginx-app-5jyvm 1/1 Running 0 1h
84+
```
85+
86+
#### docker exec
87+
88+
How do I execute a command in a container? Checkout [kubectl exec](kubectl/kubectl_exec.md).
89+
90+
With docker:
91+
```
92+
$ docker ps
93+
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
94+
a9ec34d98787 nginx "nginx -g 'daemon of 8 minutes ago Up 8 minutes 0.0.0.0:80->80/tcp, 443/tcp nginx-app
95+
$ docker exec a9ec34d98787 cat /etc/hostname
96+
a9ec34d98787
97+
```
98+
99+
With kubectl:
100+
```
101+
$ kubectl get po
102+
NAME READY STATUS RESTARTS AGE
103+
nginx-app-5jyvm 1/1 Running 0 10m
104+
$ kubectl exec nginx-app-5jyvm -- cat /etc/hostname
105+
nginx-app-5jyvm
106+
```
107+
108+
What about interactive commands?
109+
110+
111+
With docker:
112+
```
113+
$ docker exec -ti a9ec34d98787 /bin/sh
114+
# exit
115+
```
116+
117+
With kubectl:
118+
```
119+
$ kubectl exec -ti nginx-app-5jyvm -- /bin/sh
120+
# exit
121+
```
122+
123+
For more information see [Getting into containers](getting-into-containers.md).
124+
125+
#### docker logs
126+
127+
How do I follow stdout/stderr of a running process? Checkout [kubectl logs](kubectl/kubectl_logs.md).
128+
129+
130+
With docker:
131+
```
132+
$ docker logs -f a9e
133+
192.168.9.1 - - [14/Jul/2015:01:04:02 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.35.0" "-"
134+
192.168.9.1 - - [14/Jul/2015:01:04:03 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.35.0" "-"
135+
```
136+
137+
With kubectl:
138+
```
139+
$ kubectl logs -f nginx-app-zibvs
140+
10.240.63.110 - - [14/Jul/2015:01:09:01 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.26.0" "-"
141+
10.240.63.110 - - [14/Jul/2015:01:09:02 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.26.0" "-"
142+
```
143+
144+
Now's a good time to mention slight difference between pods and containers; by default pods will not terminate if their process's exit. Instead it will restart the process. This is similar to the docker run option `--restart=always` with one major difference. In docker, the output for each invocation of the process is concatenated but for Kubernetes, each invokation is separate. To see the output from a prevoius run in kubernetes, do this:
145+
146+
```
147+
$ kubectl logs --previous nginx-app-zibvs
148+
10.240.63.110 - - [14/Jul/2015:01:09:01 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.26.0" "-"
149+
10.240.63.110 - - [14/Jul/2015:01:09:02 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.26.0" "-"
150+
```
151+
152+
See [Logging](logging.md) for more information.
153+
154+
#### docker stop and docker rm
155+
156+
How do I stop and delete a running process? Checkout [kubectl delete](kubectl/kubectl_delete.md).
157+
158+
With docker
159+
```
160+
$ docker ps
161+
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
162+
a9ec34d98787 nginx "nginx -g 'daemon of 22 hours ago Up 22 hours 0.0.0.0:80->80/tcp, 443/tcp nginx-app
163+
$ docker stop a9ec34d98787
164+
a9ec34d98787
165+
$ docker rm a9ec34d98787
166+
a9ec34d98787
167+
```
168+
169+
With kubectl:
170+
```
171+
$ kubectl get rc nginx-app
172+
CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS
173+
nginx-app nginx-app nginx run=nginx-app 1
174+
$ kubectl get po
175+
NAME READY STATUS RESTARTS AGE
176+
nginx-app-aualv 1/1 Running 0 16s
177+
$ kubectl delete rc nginx-app
178+
NAME READY STATUS RESTARTS AGE
179+
nginx-app-aualv 1/1 Running 0 16s
180+
$ kubectl get po
181+
NAME READY STATUS RESTARTS AGE
182+
```
183+
184+
Notice that we don't delete the pod directly. With kubectl we want to delete the replication controller that owns the pod. If we delete the pod directly, the replication controller will recreate the pod.
185+
186+
#### docker login
187+
188+
There is no direct analog of 'docker login' in kubectl. If you are interested in using Kubernetes with a private registry, see [Using a Private Registry](images.md#using-a-private-registry).
189+
190+
#### docker version
191+
192+
How do I get the version of my client and server? Checkout [kubectl version](kubectl/kubectl_version.md).
193+
194+
With docker:
195+
```
196+
$ docker version
197+
Client version: 1.7.0
198+
Client API version: 1.19
199+
Go version (client): go1.4.2
200+
Git commit (client): 0baf609
201+
OS/Arch (client): linux/amd64
202+
Server version: 1.7.0
203+
Server API version: 1.19
204+
Go version (server): go1.4.2
205+
Git commit (server): 0baf609
206+
OS/Arch (server): linux/amd64
207+
```
208+
209+
With kubectl:
210+
```
211+
$ kubectl version
212+
Client Version: version.Info{Major:"0", Minor:"20.1", GitVersion:"v0.20.1", GitCommit:"", GitTreeState:"not a git tree"}
213+
Server Version: version.Info{Major:"0", Minor:"21+", GitVersion:"v0.21.1-411-g32699e873ae1ca-dirty", GitCommit:"32699e873ae1caa01812e41de7eab28df4358ee4", GitTreeState:"dirty"}
214+
```
215+
216+
#### docker info
217+
218+
How do I get miscellaneous info about my environment and configuration? Checkout [kubectl cluster-info](kubectl/kubectl_cluster-info.md).
219+
220+
With docker:
221+
```
222+
$ docker info
223+
Containers: 40
224+
Images: 168
225+
Storage Driver: aufs
226+
Root Dir: /usr/local/google/docker/aufs
227+
Backing Filesystem: extfs
228+
Dirs: 248
229+
Dirperm1 Supported: false
230+
Execution Driver: native-0.2
231+
Logging Driver: json-file
232+
Kernel Version: 3.13.0-53-generic
233+
Operating System: Ubuntu 14.04.2 LTS
234+
CPUs: 12
235+
Total Memory: 31.32 GiB
236+
Name: k8s-is-fun.mtv.corp.google.com
237+
ID: ADUV:GCYR:B3VJ:HMPO:LNPQ:KD5S:YKFQ:76VN:IANZ:7TFV:ZBF4:BYJO
238+
WARNING: No swap limit support
239+
```
240+
241+
With kubectl:
242+
```
243+
$ kubectl cluster-info
244+
Kubernetes master is running at https://108.59.85.141
245+
KubeDNS is running at https://108.59.85.141/api/v1/proxy/namespaces/kube-system/services/kube-dns
246+
KubeUI is running at https://108.59.85.141/api/v1/proxy/namespaces/kube-system/services/kube-ui
247+
Grafana is running at https://108.59.85.141/api/v1/proxy/namespaces/kube-system/services/monitoring-grafana
248+
Heapster is running at https://108.59.85.141/api/v1/proxy/namespaces/kube-system/services/monitoring-heapster
249+
InfluxDB is running at https://108.59.85.141/api/v1/proxy/namespaces/kube-system/services/monitoring-influxdb
250+
```
251+
252+
253+
<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
254+
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/user-guide/docker-cli-to-kubectl.md?pixel)]()
255+
<!-- END MUNGE: GENERATED_ANALYTICS -->

docs/user-guide/quick-start.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ certainly want the docs that go with that version.</h1>
3232

3333
<!-- END MUNGE: GENERATED_TOC -->
3434

35-
This guide will help you get oriented to Kubernetes and running your first containers on the cluster.
35+
This guide will help you get oriented to Kubernetes and running your first containers on the cluster. If you are already familiar with the docker-cli, you can also checkout the docker-cli to kubectl migration guide [here](docker-cli-to-kubectl.md).
36+
3637

3738
## Launching a simple application
3839

0 commit comments

Comments
 (0)