helloworld容器化构建-阿里云开发者社区

开发者社区> 云原生> 正文

helloworld容器化构建

简介: [root@ test]# cat app1.go package main import ( "net/http" "log" "fmt" ) func app1(w http.
[root@ test]# cat app1.go
package main


import (
        "net/http"
        "log"
        "fmt"
)

func app1(w http.ResponseWriter, r *http.Request){
        fmt.Println("app1")
        w.Write([]byte("app1"))
}
func app2(w http.ResponseWriter, r *http.Request){
        fmt.Println("app2")
        w.Write([]byte("app2"))
}
func app3(w http.ResponseWriter, r *http.Request){
        fmt.Println("app3")
        w.Write([]byte("app3"))
}

func main(){

        http.HandleFunc("/app1", app1)
        http.HandleFunc("/app2", app2)
        http.HandleFunc("/app3", app3)
        err := http.ListenAndServe(":5001", nil)
        if err != nil {
                log.Fatal("ListenAndServe: ", err.Error())
        }

}
[root@SZD-L0089619 test]# cat Dockerfile
From domain/official/centos:7.2.1511
COPY ./app1 /istio-test/app1


CMD ["/istio-test/app1"]
[root@ test]#
[root@ helloworld]# cat testapp.yaml
apiVersion: v1
kind: Service
metadata:
  name: testapp
  labels:
    app: testapp
spec:
  type: NodePort
  ports:
  - port: 5001
    name: http
  selector:
    app: testapp
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: testapp-v1
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: testapp
        version: v1
    spec:
      containers:
      - name: testapp
        image: domain/istio-test:v1
        resources:
          requests:
            cpu: "100m"
        imagePullPolicy: IfNotPresent #Always
        ports:
        - containerPort: 5001
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: testapp-v2
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: testapp
        version: v2
    spec:
      containers:
      - name: testapp
        image: domain/istio-test:v2
        resources:
          requests:
            cpu: "100m"
        imagePullPolicy: IfNotPresent #Always
        ports:
        - containerPort: 5001
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: testapp
  annotations:
    kubernetes.io/ingress.class: "istio"
spec:
  rules:
  - http:
      paths:
      - path: /app1
        backend:
          serviceName: testapp
          servicePort: 5001
      - path: /app2
        backend:
          serviceName: testapp
          servicePort: 5001
      - path: /app3
        backend:
          serviceName: testapp
          servicePort: 5001
---

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

分享:
云原生
使用钉钉扫一扫加入圈子
+ 订阅

云原生时代,是开发者最好的时代

其他文章