美文网首页
Kubernetes in Action 第二版 - 在K8S上

Kubernetes in Action 第二版 - 在K8S上

作者: 老谭涮菜 | 来源:发表于2021-01-14 11:37 被阅读0次

    Creating a Deployment

    $ kubectl create deployment kubia --image=luksa/kubia:1.0
    deployment.apps/kubia created
    

    Listing deployments

    $ kubectl get deployments
    NAME    READY   UP-TO-DATE   AVAILABLE   AGE
    kubia   0/1     1            0           6s
    

    Listing pods

    Listing 3.11 Listing pods
    $ kubectl get pods
    NAME                     READY     STATUS    RESTARTS   AGE
    kubia-9d785b578-p449x    0/1       Pending   0          1m
    
    Listing 3.12 The events displayed by kubectl describe pod
    Events:
    Type    Reason     Age   From               Message
    ----    ------     ----  ----               -------
    Normal  Scheduled  25s   default-scheduler  Successfully assigned
                                                default/kubia-9d785b578-p449x
                                                to worker2
    Normal  Pulling    23s   kubelet, worker2   Pulling image "luksa/kubia:1.0"
    Normal  Pulled     21s   kubelet, worker2   Successfully pulled image
    Normal  Created    21s   kubelet, worker2   Created container kubia
    Normal  Started    21s   kubelet, worker2   Started container kubia
    

    Creating a Service

    $ kubectl expose deployment kubia --type=LoadBalancer --port 8080
    service/kubia exposed
    

    Listing services

    Listing 3.13 Listing Services
    $ kubectl get svc
    NAME         TYPE          CLUSTER-IP     EXTERNAL-IP   PORT(S)         AGE
    kubernetes   ClusterIP     10.19.240.1    <none>        443/TCP         34m
    kubia        LoadBalancer  10.19.243.17   <pending>     8080:30838/TCP  4s
    
    Listing 3.14 Getting a single service
    $ kubectl get svc kubia
    NAME        TYPE          CLUSTER-IP    EXTERNAL-IP    PORT(S)         AGE
    kubia       LoadBalancer  10.19.243.17  35.246.179.22  8080:30838/TCP  82s
    

    Accessing your application through the load balance

    $ curl 35.246.179.22:8080
    Hey there, this is kubia-9d785b578-p449x. Your IP is ::ffff:1.2.3.4.
    

    Increasing the number of running application instances

    $ kubectl scale deployment kubia --replicas=3
    deployment.apps/kubia scaled
    

    Seeing the results of the scale-out

    $ kubectl get deploy
    NAME    READY   UP-TO-DATE   AVAILABLE   AGE
    kubia   3/3     3            3           18m
    
    $ kubectl get pods
    NAME                    READY   STATUS    RESTARTS   AGE
    kubia-9d785b578-58vhc   1/1     Running   0          17s
    kubia-9d785b578-jmnj8   1/1     Running   0          17s
    kubia-9d785b578-p449x   1/1     Running   0          18m
    

    Displaying the pods’ host node when listing pods

    $ kubectl get pods -o wide
    NAME                   ...  IP          NODE
    kubia-9d785b578-58vhc  ...  10.244.1.5  worker1
    kubia-9d785b578-jmnj8  ...  10.244.2.4  worker2
    kubia-9d785b578-p449x  ...  10.244.2.3  worker2
    

    Understanding the API objects representing your application

    Listing 3.16 Requests sent to the service are spread across all the pods
    $ curl 35.246.179.22:8080
    Hey there, this is kubia-9d785b578-58vhc. Your IP is ::ffff:1.2.3.4.
    $ curl 35.246.179.22:8080
    Hey there, this is kubia-9d785b578-p449x. Your IP is ::ffff:1.2.3.4.
    $ curl 35.246.179.22:8080
    Hey there, this is kubia-9d785b578-jmnj8. Your IP is ::ffff:1.2.3.4.
    $ curl 35.246.179.22:8080
    Hey there, this is kubia-9d785b578-p449x. Your IP is ::ffff:1.2.3.4.
    

    相关文章

      网友评论

          本文标题:Kubernetes in Action 第二版 - 在K8S上

          本文链接:https://www.haomeiwen.com/subject/xpxvaktx.html