发布时间: 2024-7-8 文章作者: myluzh 分类名称: Kubernetes 朗读文章
root@iZbp12bkuvg20e1j3y9gtxZ:~/# kubectl get svc -n istio-system | grep ingress istio-ingressgateway NodePort 10.43.160.137 <none> 15021:31016/TCP,80:30058/TCP,443:30605/TCP,31400:32117/TCP,15443:32636/TCP 87d
kubectl create ns myluzh kubectl label namespace default istio-injection=enabled2、部署应用和服务
# kubectl apply -f hellok8s -n myluzh apiVersion: apps/v1 kind: Deployment metadata: name: hellok8s spec: replicas: 4 selector: matchLabels: app: hellok8s template: metadata: labels: app: hellok8s spec: containers: - name: hellok8s imagePullPolicy: Always image: registry.cn-hangzhou.aliyuncs.com/myluzh/hellok8s:v3 --- apiVersion: v1 kind: Service metadata: name: hellok8s spec: selector: app: hellok8s type: NodePort ports: - port: 80 targetPort: 80 nodePort: 31000查看应用是否正常运行:
root@iZbp12bkuvg20e1j3y9gtxZ:~/myluzh# kubectl get deployment,svc -n myluzh NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/hellok8s 3/4 4 3 4m36s NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/hellok8s NodePort 10.43.189.6 <none> 80:31000/TCP 4m36s3、配置Gateway跟VirtualService
apiVersion: networking.istio.io/v1alpha3 kind: Gateway metadata: name: gw-hellok8s namespace: myluzh spec: selector: istio: ingressgateway # 使用 Istio IngressGateway servers: - port: number: 80 name: http protocol: HTTP hosts: - "*" --- apiVersion: networking.istio.io/v1alpha3 kind: VirtualService metadata: name: vs-hellok8s namespace: myluzh spec: hosts: - "*" gateways: - gw-hellok8s http: - match: - uri: prefix: "/" route: - destination: host: hellok8s # 应用svc名称 port: number: 80 protocol: HTTP验证是否生效:
root@iZbp12bkuvg20e1j3y9gtxZ:~/myluzh# kubectl get gw,vs -n myluzh NAME AGE gateway.networking.istio.io/gw-hellok8s 24m NAME GATEWAYS HOSTS AGE virtualservice.networking.istio.io/vs-hellok8s ["gw-hellok8s"] ["*"] 24m使用curl测试:
root@iZbp12bkuvg20e1j3y9gtxZ:~/myluzh# curl 127.0.0.1:30058 ... <title>Hello, K8S!</title> ...
标签: k8s Ingress istio istio-ingressgateway gateway virtualservice
发表评论