Kubernetes叢集部署tomcat容器/Java web應用流程-docker cp方式

來源:互聯網
上載者:User
kube-tomcat.yaml實現如下。 這裡是把Deployment和Services在一個檔案中實現了。也可以分為兩個檔案來實現。 # Copyright 2015 Google Inc. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # #      http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License.
# Configuration to deploy release version of the Dashboard UI. # # Example usage: kubectl create -f <this_file>
kind: Deployment apiVersion: extensions/v1beta1 metadata:   labels:     app: kube-tomcat     version: v1.1.1   name: kube-tomcat   namespace: default spec:   replicas: 1   selector:     matchLabels:       app: kube-tomcat   template:     metadata:       labels:         app: kube-tomcat     spec:       containers:       - name: kube-tomcat         image: docker.io/chenyufeng/tomcat-centos         imagePullPolicy: Always         ports:         - containerPort: 8080           protocol: TCP         args:           # Uncomment the following line to manually specify Kubernetes API server Host           # If not specified, Dashboard will attempt to auto discover the API server and connect           # to it. Uncomment only if the default does not work.         - --apiserver-host=http://47.97.90.38:8080  ## 請修改為自己的kube-apiserver         livenessProbe:           httpGet:             path: /             port: 8080           initialDelaySeconds: 30           timeoutSeconds: 30 --- kind: Service apiVersion: v1 metadata:   labels:     app: kube-tomcat   name: kube-tomcat   namespace: default spec:   type: NodePort   ports:   - port: 80     targetPort: 8080   selector:     app: kube-tomcat
完整的檔案如下:
在master上,然後使用如下命令建立deployment和Service kubectl create -f  kube-tomcat.yaml
查看建立的deployment: kubectl get deployment


查看這個deployment的詳情: kubectl describe deployment kube-tomcat


查看建立的service: kubectl get service

查看這個service的詳情。 kubectl describe service kube-tomcat service詳情這裡的IP就是CLUSTER-IP. CLUSTER-IP是和service綁定的。 service詳情這裡的Port就是Service的連接埠號碼。 service詳情這裡的NodePort就是Node的真實連接埠號碼。 service詳情這裡的Endpoints就是容器的IP和port。

查看建立的pod: kubectl get pod


查看其中一個pod的詳情。  pod詳情這裡的IP是nodes中的虛擬IP。該虛擬IP可以去nodes裡面使用ifconfig查看。 kubectl describe pod kube-tomcat-1115055280-tk1f8



在 nodes 上查看建立的容器:
然後使用瀏覽器訪問:http://47.97.90.38:8080/api/v1/proxy/namespaces/default/services/kube-tomcat/ 這裡一定要指定namespaces和services。
然後到nodes中,把war使用“docker cp”複製到容器的tomcat/webapps,就可以實現頁面的訪問了【這裡可能需要等待較多時間,至少幾分鐘】 在Postman中進行測試 注意在請求中的IP應該是master所在的IP。返回成功。可以使用Postman來進行介面測試,測試通過表示部署成功。

以上步驟的部署也可以結合持續整合CI/CD來進行,能簡化不少流程。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.