1. 程式人生 > >Kubernetes系列之三:部署你的第一個應用程式到k8s叢集

Kubernetes系列之三:部署你的第一個應用程式到k8s叢集

部署你的第一個應用程式到k8s叢集

看到這裡,求知慾飢渴難耐的你一定在想,怎麼部署的我們應用程式到叢集裡面去呢?來個簡單的,只需要兩步:(這裡本文使用nginx映象當我們的應用程式,因為nginx 簡單,執行起來後直接可以用瀏覽器訪問網頁了。)

第一步:在master 節點上建立一個deployment

kubectl create deployment nginx --image=nginx

效果如下,可以看到一個叫nginx的deployment建立成功了。

[email protected]:/home/cong# kubectl create deployment nginx --image=nginx
deployment.apps/nginx created
 
[email protected]
:/home/cong# kubectl get deployments NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE nginx 1 1 1 1 11m

第二步:建立一個service

kubectl create service nodeport nginx --tcp 80:80

效果如下,可以看到一個叫nginx的service建立成功了,這裡kubectl get svc是kubectl get services的簡寫。

[email protected]:/home/cong# kubectl create service nodeport nginx --tcp 80:80
service/nginx created
 
[email protected]:/home/cong# kubectl get svc
NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
kubernetes   ClusterIP   10.96.0.1        <none>        443/TCP        3d
nginx        NodePort    10.107.237.157   <none>        80:30601/TCP   11s

在slave節點上執行下面的命令驗證一下nginx有沒有部署成功。

curl localhost:30601

或者

curl kube-slave:30601

效果如下:

[email protected]:/home/cong# curl localhost:30601
<!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>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
 
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
 
<p><em>Thank you for using nginx.</em></p>
</body>
</html>

用瀏覽器開啟試試,nginx的首頁顯示出來了。

簡單吧,是不是信心大增了?!

為了練習更多複雜的命令,我們將上面建好的deployments/nginx, services/nginx 刪除先,命令如下:

[email protected]:/home/cong# kubectl delete deployments/nginx services/nginx
deployment.extensions "nginx" deleted
service "nginx" deleted

好了,你應用程式部署的處女作就完美結束了

作者:wucong60
來源:CSDN
原文:https://blog.csdn.net/wucong60/article/details/81458409
版權宣告:本文為博主原創文章,轉載請附上博文連結!