kubectl管理kubernetes集群

[root@master ~]# kubectl get nodes  查看集群节点
NAME      STATUS    AGE
node1    Ready    25m
node2    Ready    19m
[root@master ~]# kubectl version  查看版本
Client Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.2", GitCommit:"269f928217957e7126dc87e6adfa82242bfe5b1e", GitTreeState:"clean", BuildDate:"2017-07-03T15:31:10Z", GoVersion:"go1.7.4", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.2", GitCommit:"269f928217957e7126dc87e6adfa82242bfe5b1e", GitTreeState:"clean", BuildDate:"2017-07-03T15:31:10Z", GoVersion:"go1.7.4", Compiler:"gc", Platform:"linux/amd64"}
[root@master ~]# kubectl run nginx --image=docker.io/nginx --replicas=1 --port=9000
deployment "nginx" created
[root@master ~]# kubectl get deployment
NAME      DESIRED  CURRENT  UP-TO-DATE  AVAILABLE  AGE
nginx    1        1        1            0          15s
[root@master ~]# kubectl get pods
NAME                    READY    STATUS    RESTARTS  AGE
nginx-2187705812-8r0h4  1/1      Running  0          1h
[root@master ~]# kubectl get pods -o wide
NAME                    READY    STATUS    RESTARTS  AGE      IP          NODE
nginx-2187705812-8r0h4  1/1      Running  0          1h        10.255.4.2  node1
想要删除一个容器的时候:

[root@master ~]# kubectl delete pod nginx-2187705812-8r0h4
pod "nginx-2187705812-8r0h4" deleted
[root@master ~]# kubectl get pod
NAME                    READY    STATUS              RESTARTS  AGE
nginx-2187705812-6dn2r  0/1      ContainerCreating  0          4s
删除了之后还依然有,这个是因为创建deployment的时候参数--replicas=1起作用了。想要删除的话直接删除deployment就可以了。

[root@master ~]# kubectl delete deployment nginx
deployment "nginx" deleted

yaml语法:

[root@master ~]# kubectl create -f MySQL-deployment.yaml
deployment "mysql" created
[root@master ~]# kubectl get deployment
NAME      DESIRED  CURRENT  UP-TO-DATE  AVAILABLE  AGE
mysql    1        1        1            1          9s
[root@master ~]# kubectl get pods -o wide
NAME                    READY    STATUS    RESTARTS  AGE      IP          NODE
mysql-2261771434-r8td1  1/1      Running  0          16s      10.255.4.2  node1
在node1上查看mysql docker实例

[root@node1 ~]# docker ps -a
CONTAINER ID        IMAGE                                                        COMMAND                  CREATED            STATUS                    PORTS              NAMES
e33797549b8e        docker.io/mysql/mysql-server                                "/entrypoint.sh my..."  4 minutes ago      Up 4 minutes (healthy)                        k8s_mysql.31ec27ee_mysql-2261771434-r8td1_default_351da1d4-f082-11e8-bbf2-000c297d60e3_089418b7

kubectl其他参数:

logs      取得pod中容器的log信息

exec    在容器中执行一条命令

cp        从容器拷出或者想容器中拷入文件

attach    attach到一个运行的容器上

logs

[root@master ~]# kubectl get pod
NAME                    READY    STATUS    RESTARTS  AGE
mysql-2261771434-r8td1  1/1      Running  0          18m
[root@master ~]# kubectl logs mysql-2261771434-r8td1
[Entrypoint] MySQL Docker Image 5.7.20-1.1.2
[Entrypoint] Initializing database
[Entrypoint] Database initialized
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
[Entrypoint] ignoring /docker-entrypoint-initdb.d/*
[Entrypoint] Server shut down
[Entrypoint] MySQL init process done. Ready for start up.
[Entrypoint] Starting MySQL 5.7.20-1.1.2

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/4ae6b4aba8cc6606d48d4325abbf04a2.html