[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
---