Kubernetes常用操作手册

应用管理:快速上手

启动一个简单应用

建议在minion节点提前下载好nginx镜像(docker pull nginx
$ kubectl run my-nginx --image=nginx --replicas=2 --port=80
CONTROLLER   CONTAINER(S)   IMAGE(S)   SELECTOR       REPLICAS
my-nginx     my-nginx       nginx      run=my-nginx   2
$ kubectl get po
NAME             READY     STATUS    RESTARTS   AGE
my-nginx-l8n3i   1/1       Running   0          29m
my-nginx-q7jo3   1/1       Running   0          29m

Kubernetes将确保您的应用程序保持运行,当某个容器发生异常,Kubernetes会自动创建新的容器,确保有制定数据的容器在运行。

暴露你的应用到公网

$ kubectl expose rc my-nginx --port=80 --type=LoadBalancer
service "my-nginx" exposed
$ kubectl get svc my-nginx
NAME         CLUSTER_IP       EXTERNAL_IP       PORT(S)                SELECTOR     AGE
my-nginx     10.179.240.1     25.1.2.3          80/TCP                 run=nginx    8d

杀死应用

$ kubectl delete rc my-nginx
replicationcontrollers/my-nginx
$ kubectl delete svc my-nginx
services/my-nginx

参考文章