docker和k8s的常见命令
docker
docker run
创建⼀个新的容器并运⾏⼀个命令。
docker run [OPTIONS] IMAGE [COMMAND] []
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
列出所有运⾏的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 Serve
r number: 8.5.24.0
docker进入容器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
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论