docker

  • docker run
    创建一个新的容器并运行一个命令。
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
sudo docker run -d -p 5000:5000 training/webapp python app.py //将容器的5000端口映射到内部的5000端口
  • docker ps
    查看正在运行的容器。

  • docker images
    列出本地存储的镜像。

  • docker stop [containerid]
    停止容器

  • docker exec
    在容器中执行命令

  • docker exec -it [containerid] /bin/bash
    进入容器

  • docker build
    首先要准备一个docker file

  • docker pull
    默认从DockerHub上拉取镜像。

  • docker rm
    删除镜像

docker-compose(三剑客之一)

如果涉及多个容器的运行(如服务编排)就可以通过 docker-compose 来实现,它可以轻松的将多个容器作为 service 来运行(当然也可仅运行其中的某个),并且提供了 scale (服务扩容) 的功能。
简单而言,dockerfile可以让你配置运行一个容器,但是docker-compose可以让你一条命令运行多个配置的容器

docker-machine(三剑客之一)

简单来说就是给你快速创建一个docker容器环境的,怎么说呢,如果你要给100台阿里云ECS安装上docker,传统方式就是你一台一台ssh上去安装,但是有了docker-machine就不一样了

docker-swarm(三剑客之一)

和 Docker Compose 一样,都是 Docker 官方容器编排项目,但不同的是,Docker Compose 是一个在单个服务器或主机上创建多个容器的工具,而 Docker Swarm 则可以在多个服务器或主机上创建容器集群服务,对于微服务的部署,显然 Docker Swarm 会更加适合。

kubectl get

http://docs.kubernetes.org.cn/626.html

列出所有运行的Pod信息。

$ kubectl get pods
NAME                        READY     STATUS    RESTARTS   AGE
busybox                     1/1       Running   22         22h
my-nginx-2507610963-q07sh   1/1       Running   0          1d
my-nginx-2507610963-z0krm   1/1       Running   0          1d
myweb-gnz95                 1/1       Running   0          4d
myweb-k5l8w                 1/1       Running   0          4d

查看所有节点

@master-k8s ~]$ kubectl get nodes
NAME                STATUS    AGE       VERSION
node1-k8s.umetrip   Ready     5d        v1.7.16
node2-k8s.umetrip   Ready     5d        v1.7.16
node3-k8s.umetrip   Ready     5d        v1.7.16
node4-k8s.umetrip   Ready     5d        v1.7.16

查看所有RC和SVC

master-k8s gdl_test]$  kubectl get rc,svc
NAME        DESIRED   CURRENT   READY     AGE
rc/gdlweb   2         2         2         7m
rc/myweb    2         2         2         11m

NAME             CLUSTER-IP        EXTERNAL-IP   PORT(S)          AGE
svc/gdlweb       169.169.28.35     <nodes>       8080:30005/TCP   7m
svc/kubernetes   169.169.0.1       <none>        443/TCP          5d
svc/my-nginx     169.169.244.232   <none>        80/TCP           1d
svc/myweb        169.169.77.217    <nodes>       8080:30001/TCP   11m

显示所有信息。

master-k8s gdl_test]$ kubectl get all
NAME                           READY     STATUS             RESTARTS   AGE
po/busybox                     1/1       Running            25         1d
po/gdlweb-6gjvj                1/1       Running            0          18m
po/gdlweb-djxnb                1/1       Running            0          18m
po/my-nginx-2507610963-q07sh   1/1       Running            0          1d
po/my-nginx-2507610963-z0krm   1/1       Running            0          1d
po/myweb-qhv8q                 1/1       Running            0          22m
po/myweb-tvwsl                 1/1       Running            0          22m
po/nginx-4217019353-mfzld      0/1       ImagePullBackOff   0          1h

NAME        DESIRED   CURRENT   READY     AGE
rc/gdlweb   2         2         2         18m
rc/myweb    2         2         2         22m

NAME             CLUSTER-IP        EXTERNAL-IP   PORT(S)          AGE
svc/gdlweb       169.169.28.35     <nodes>       8080:30005/TCP   18m
svc/kubernetes   169.169.0.1       <none>        443/TCP          5d
svc/my-nginx     169.169.244.232   <none>        80/TCP           1d
svc/myweb        169.169.77.217    <nodes>       8080:30001/TCP   22m

NAME              DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
deploy/my-nginx   2         2         2            2           1d
deploy/nginx      1         1         1            0           1h

NAME                     DESIRED   CURRENT   READY     AGE
rs/my-nginx-2507610963   2         2         2         1d
rs/nginx-4217019353      1         1         0         1h

kubectl create

rc.yaml的文件实例如下

apiVersion: v1
kind: ReplicationController
metadata:
  name: gdlweb
spec:
  replicas: 2
  selector:
    app: gdlweb
  template:
    metadata:
      labels:
        app: gdlweb
    spec:
      containers:
      - name: gdlweb
        image: 10.237.65.192:1179/tomcat
        ports:
        - containerPort: 8080
        env:
        - name: MYSQL_SERVICE_HOST
          value: 'mysql'
        - name: MYSQL_SERVICE_PORT
          value: '3306'

svc.yaml的实例如下

apiVersion: v1
kind: Service
metadata:
  name: gdlweb
spec:
  type: NodePort
  ports:
    - port: 8080
      nodePort: 30005
  selector:
    app: gdlweb

kubectl logs

查看节点日志。

master-k8s gdl_test]$ kubectl logs gdlweb-6gjvj
14-Nov-2018 07:39:11.668 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version:        Apache Tomcat/8.5.24
14-Nov-2018 07:39:11.670 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          Nov 27 2017 13:05:30 UTC
14-Nov-2018 07:39:11.670 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number:         8.5.24.0
14-Nov-2018 07:39:11.670 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Linux
14-Nov-2018 07:39:11.670 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:            3.10.0-514.el7.x86_64
14-Nov-2018 07:39:11.670 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:          amd64
14-Nov-2018 07:39:11.670 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:             /usr/lib/jvm/java-8-openjdk-amd64/jre
14-Nov-2018 07:39:11.670 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version:           1.8.0_151-8u151-b12-1~deb9u1-b12
14-Nov-2018 07:39:11.670 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:            Oracle Corporation
14-Nov-2018 07:39:11.671 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:         /usr/local/tomcat
14-Nov-2018 07:39:11.671 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:         /usr/local/tomcat

kubectl exec

## 登陆容器
kubectl exec -it gdlweb-6gjvj  -- bash

kubectl delete

关闭某个服务。

master-k8s gdl_test]$ kubectl delete -f .
replicationcontroller "gdlweb" deleted
service "gdlweb" deleted

kubectl cluster-info

查看集群已经安装的插件

kubectl cluster-info
Kubernetes master is running at 10.237.65.192:1180
KubeDNS is running at 10.237.65.192:1180/api/v1/namespaces/kube-system/services/kube-dns/proxy

kubectl api-versions

查看集群的API版本。

$ kubectl api-versions
apiextensions.k8s.io/v1beta1
apiregistration.k8s.io/v1beta1
apps/v1beta1
authentication.k8s.io/v1
authentication.k8s.io/v1beta1
authorization.k8s.io/v1
authorization.k8s.io/v1beta1
autoscaling/v1
batch/v1
certificates.k8s.io/v1beta1
extensions/v1beta1
networking.k8s.io/v1
policy/v1beta1
rbac.authorization.k8s.io/v1alpha1
rbac.authorization.k8s.io/v1beta1
settings.k8s.io/v1alpha1
storage.k8s.io/v1
storage.k8s.io/v1beta1
v1
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐