【发布时间】:2021-05-27 18:54:57
【问题描述】:
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: hello-k8s
spec:
hosts:
- ???
http:
- name: hello-k8s
match:
- uri:
prefix: /
route:
- destination:
host: hello # <--------------
port:
number: 8080
将项目部署到我本地的 minikube 后:
- 我应该将请求发送到哪个域名?
hello.local?
$ curl what.should.be.here:8080
- 有没有办法使用
kubectl和自省来找出它?
更新 1:
我把主机改成了hello.local。
然后我验证istio在minikube中启用:
➜ minikube addons list
|-----------------------------|----------|--------------|
| ADDON NAME | PROFILE | STATUS |
|-----------------------------|----------|--------------|
| ambassador | minikube | disabled |
| csi-hostpath-driver | minikube | disabled |
| dashboard | minikube | disabled |
| default-storageclass | minikube | enabled ✓ |
| efk | minikube | disabled |
| freshpod | minikube | disabled |
| gcp-auth | minikube | disabled |
| gvisor | minikube | disabled |
| helm-tiller | minikube | disabled |
| ingress | minikube | disabled |
| ingress-dns | minikube | disabled |
| istio | minikube | enabled ✓ |
| istio-provisioner | minikube | enabled ✓ |
| kubevirt | minikube | disabled |
| logviewer | minikube | disabled |
| metallb | minikube | disabled |
| metrics-server | minikube | disabled |
| nvidia-driver-installer | minikube | disabled |
| nvidia-gpu-device-plugin | minikube | disabled |
| olm | minikube | disabled |
| pod-security-policy | minikube | disabled |
| registry | minikube | disabled |
| registry-aliases | minikube | disabled |
| registry-creds | minikube | disabled |
| storage-provisioner | minikube | enabled ✓ |
| storage-provisioner-gluster | minikube | disabled |
| volumesnapshots | minikube | disabled |
|-----------------------------|----------|--------------|
我部署了应用程序并验证一切正常:
➜ kubectl apply -k base/
service/hello-k8s unchanged
deployment.apps/hello-k8s unchanged
virtualservice.networking.istio.io/hello-k8s configured
➜ kubectl get deployments/hello-k8s
NAME READY UP-TO-DATE AVAILABLE AGE
hello-k8s 1/1 1 1 20h
➜ kubectl get pods
NAME READY STATUS RESTARTS AGE
hello-k8s-6d9cc7d655-plzs8 1/1 Running 0 20h
➜ kubectl get service/hello-k8s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hello-k8s ClusterIP 10.98.144.226 <none> 8080/TCP 21h
➜ kubectl get virtualservice/hello-k8s
NAME GATEWAYS HOSTS AGE
hello-k8s ["hello.local"] 20h
➜ kubectl get pods -n istio-system
NAME READY STATUS RESTARTS AGE
istio-ingressgateway-8577c95547-6c9sk 1/1 Running 0 21h
istiod-6ccd677dc7-7cvr2 1/1 Running 0 21h
prometheus-7767dfd55-x2pv6 2/2 Running 0 21h
不知道为什么我必须这样做,但显然应该这样做:
➜ kubectl label namespace default istio-injection=enabled --overwrite
namespace/default labeled
➜ kubectl get namespace -L istio-injection
NAME STATUS AGE ISTIO-INJECTION
default Active 21h enabled
istio-operator Active 21h
istio-system Active 21h disabled
kube-node-lease Active 21h
kube-public Active 21h
kube-system Active 21h
playground Active 21h
我检查了minikube 的IP,并在/etc/hosts 中添加了hello.local 的条目:
➜ minikube ip
192.168.49.2
➜ tail -n 3 /etc/hosts
# Minikube
192.168.49.2 hello.local
然后我根据this blog post查询istio-ingressgateway的端口:
➜ kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}'
30616
最后我向hello.local:30616 发送了一个请求,但请求没有到达我的应用程序:
➜ curl -iv hello.local:30616/hello
* Trying 192.168.49.2:30616...
* TCP_NODELAY set
* Connected to hello.local (192.168.49.2) port 30616 (#0)
> GET /hello HTTP/1.1
> Host: hello.local:30616
> User-Agent: curl/7.68.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 404 Not Found
HTTP/1.1 404 Not Found
< date: Thu, 25 Feb 2021 14:51:18 GMT
date: Thu, 25 Feb 2021 14:51:18 GMT
< server: istio-envoy
server: istio-envoy
< content-length: 0
content-length: 0
<
* Connection #0 to host hello.local left intact
【问题讨论】:
-
你好@Behrang,你的问题还没有解决吗?
标签: kubernetes istio minikube