Kubernetes(八)集群运行实例测试

  • A+
所属分类:Kubernetes

master创建nginx容器,副本3个

[root@k8s-master bin]# kubectl run nginx --image=nginx --replicas=3
deployment "nginx" created

查看正在创建

[root@k8s-master bin]# kubectl get pod
NAME                    READY     STATUS              RESTARTS   AGE
nginx-dbddb74b8-ll6nr   0/1       ContainerCreating   0          31s
nginx-dbddb74b8-lrf22   0/1       ContainerCreating   0          31s
nginx-dbddb74b8-nz2r2   0/1       ContainerCreating   0          31s

查看运行中

[root@k8s-master bin]# kubectl get pod
NAME                    READY     STATUS    RESTARTS   AGE
nginx-dbddb74b8-ll6nr   1/1       Running   0          4m
nginx-dbddb74b8-lrf22   1/1       Running   0          4m
nginx-dbddb74b8-nz2r2   1/1       Running   0          4m

查看所有信息

[root@k8s-master bin]# kubectl get all
NAME           DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
deploy/nginx   3         3         3            3           4m

NAME                 DESIRED   CURRENT   READY     AGE
rs/nginx-dbddb74b8   3         3         3         4m

NAME                       READY     STATUS    RESTARTS   AGE
po/nginx-dbddb74b8-ll6nr   1/1       Running   0          4m
po/nginx-dbddb74b8-lrf22   1/1       Running   0          4m
po/nginx-dbddb74b8-nz2r2   1/1       Running   0          4m

NAME             TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
svc/kubernetes   ClusterIP   10.10.10.1   <none>        443/TCP   1h

查看容器运行在哪台node主机

[root@k8s-master bin]# kubectl get pod -o wide
NAME                    READY     STATUS    RESTARTS   AGE       IP            NODE
nginx-dbddb74b8-ll6nr   1/1       Running   0          5m        172.17.5.2    192.168.20.213
nginx-dbddb74b8-lrf22   1/1       Running   0          5m        172.17.44.3   192.168.20.212
nginx-dbddb74b8-nz2r2   1/1       Running   0          5m        172.17.44.2   192.168.20.212

发布一个nginx

[root@k8s-master bin]# kubectl expose deployment nginx --port=88 --target-port=80 --type=NodePort
service "nginx" exposed

查看发布的服务

[root@k8s-master bin]# kubectl get svc
NAME         TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
kubernetes   ClusterIP   10.10.10.1     <none>        443/TCP        1h
nginx        NodePort    10.10.10.182   <none>        88:48394/TCP   39s

查看某一个服务

[root@k8s-master bin]# kubectl get svc nginx

在node节点,可以通过地址访问nginx,只能在node访问,因为master没部署flanneld

[root@k8s-node02 cfg]# curl 10.10.10.182:88
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>

查看pod日志

[root@k8s-master bin]# kubectl get pod
NAME                    READY     STATUS    RESTARTS   AGE
nginx-dbddb74b8-ll6nr   1/1       Running   0          20m
nginx-dbddb74b8-lrf22   1/1       Running   0          20m
nginx-dbddb74b8-nz2r2   1/1       Running   0          20m

[root@k8s-master bin]# kubectl logs nginx-dbddb74b8-ll6nr
192.168.20.213 - - [22/Jan/2019:11:09:29 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.29.0" "-"

YaLei

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: