4.1 环境介绍

  K8s 1.9 以上版本。

4.2 快速部署Istio

  下载:  https://github.com/istio/istio/releases/,  下载 1.1.0-snapshot.5/istio-1.1.0-snapshot.5-linux.tar.gz

   1:   wget   https://github.com/istio/istio/releases/download/1.1.0-snapshot.5/istio-1.1.0-snapshot.5-linux.tar.gz

2:    tar       -xzvf     istio-1.1.0-snapshot.5-linux.tar.gz

   3:   将bin目录中的istioctl复制到一个PATH包含的路径中:

    cp     bin/istioctl      /usr/local/bin

4:  kubectl    apply    -f      install/kubernetes/istio-demo.yaml

namespace "istio-system" created
customresourcedefinition.apiextensions.k8s.io "virtualservices.networking.istio.io" created
customresourcedefinition.apiextensions.k8s.io "destinationrules.networking.istio.io" created
customresourcedefinition.apiextensions.k8s.io "serviceentries.networking.istio.io" created
customresourcedefinition.apiextensions.k8s.io "gateways.networking.istio.io" created
customresourcedefinition.apiextensions.k8s.io "envoyfilters.networking.istio.io" created
customresourcedefinition.apiextensions.k8s.io "clusterrbacconfigs.rbac.istio.io" created
customresourcedefinition.apiextensions.k8s.io "policies.authentication.istio.io" created
customresourcedefinition.apiextensions.k8s.io "meshpolicies.authentication.istio.io" created
customresourcedefinition.apiextensions.k8s.io "httpapispecbindings.config.istio.io" created
customresourcedefinition.apiextensions.k8s.io "httpapispecs.config.istio.io" created
customresourcedefinition.apiextensions.k8s.io "quotaspecbindings.config.istio.io" created
customresourcedefinition.apiextensions.k8s.io "quotaspecs.config.istio.io" created
customresourcedefinition.apiextensions.k8s.io "rules.config.istio.io" created
customresourcedefinition.apiextensions.k8s.io "attributemanifests.config.istio.io" created
customresourcedefinition.apiextensions.k8s.io "bypasses.config.istio.io" created
customresourcedefinition.apiextensions.k8s.io "circonuses.config.istio.io" created
customresourcedefinition.apiextensions.k8s.io "deniers.config.istio.io" created
customresourcedefinition.apiextensions.k8s.io "fluentds.config.istio.io" created
customresourcedefinition.apiextensions.k8s.io "kubernetesenvs.config.istio.io" created
customresourcedefinition.apiextensions.k8s.io "listcheckers.config.istio.io" created
customresourcedefinition.apiextensions.k8s.io "memquotas.config.istio.io" created
customresourcedefinition.apiextensions.k8s.io "noops.config.istio.io" created
customresourcedefinition.apiextensions.k8s.io "opas.config.istio.io" created
customresourcedefinition.apiextensions.k8s.io "prometheuses.config.istio.io" created
customresourcedefinition.apiextensions.k8s.io "rbacs.config.istio.io" created
customresourcedefinition.apiextensions.k8s.io "redisquotas.config.istio.io" created
customresourcedefinition.apiextensions.k8s.io "servicecontrols.config.istio.io" created
customresourcedefinition.apiextensions.k8s.io "signalfxs.config.istio.io" created
customresourcedefinition.apiextensions.k8s.io "solarwindses.config.istio.io" created
customresourcedefinition.apiextensions.k8s.io "stackdrivers.config.istio.io" created
customresourcedefinition.apiextensions.k8s.io "statsds.config.istio.io" created
customresourcedefinition.apiextensions.k8s.io "stdios.config.istio.io" created
customresourcedefinition.apiextensions.k8s.io "apikeys.config.istio.io" created
customresourcedefinition.apiextensions.k8s.io "authorizations.config.istio.io" created
customresourcedefinition.apiextensions.k8s.io "checknothings.config.istio.io" created
customresourcedefinition.apiextensions.k8s.io "kuberneteses.config.istio.io" created
customresourcedefinition.apiextensions.k8s.io "listentries.config.istio.io" created
customresourcedefinition.apiextensions.k8s.io "logentries.config.istio.io" created
customresourcedefinition.apiextensions.k8s.io "edges.config.istio.io" created
customresourcedefinition.apiextensions.k8s.io "metrics.config.istio.io" created
customresourcedefinition.apiextensions.k8s.io "quotas.config.istio.io" created
customresourcedefinition.apiextensions.k8s.io "reportnothings.config.istio.io" created
customresourcedefinition.apiextensions.k8s.io "servicecontrolreports.config.istio.io" created
customresourcedefinition.apiextensions.k8s.io "tracespans.config.istio.io" created
customresourcedefinition.apiextensions.k8s.io "rbacconfigs.rbac.istio.io" created
customresourcedefinition.apiextensions.k8s.io "serviceroles.rbac.istio.io" created
customresourcedefinition.apiextensions.k8s.io "servicerolebindings.rbac.istio.io" created
customresourcedefinition.apiextensions.k8s.io "adapters.config.istio.io" created
customresourcedefinition.apiextensions.k8s.io "instances.config.istio.io" created
customresourcedefinition.apiextensions.k8s.io "templates.config.istio.io" created
customresourcedefinition.apiextensions.k8s.io "handlers.config.istio.io" created
customresourcedefinition.apiextensions.k8s.io "cloudwatches.config.istio.io" created
customresourcedefinition.apiextensions.k8s.io "dogstatsds.config.istio.io" created
customresourcedefinition.apiextensions.k8s.io "sidecars.networking.istio.io" created
customresourcedefinition.apiextensions.k8s.io "clusterissuers.certmanager.k8s.io" created
customresourcedefinition.apiextensions.k8s.io "issuers.certmanager.k8s.io" created
customresourcedefinition.apiextensions.k8s.io "certificates.certmanager.k8s.io" created
configmap "istio-galley-configuration" created
configmap "istio-grafana-custom-resources" created
configmap "istio-grafana-configuration-dashboards-galley-dashboard" created
configmap "istio-grafana-configuration-dashboards-istio-mesh-dashboard" created
configmap "istio-grafana-configuration-dashboards-istio-performance-dashboard" created
configmap "istio-grafana-configuration-dashboards-istio-service-dashboard" created
configmap "istio-grafana-configuration-dashboards-istio-workload-dashboard" created
configmap "istio-grafana-configuration-dashboards-mixer-dashboard" created
configmap "istio-grafana-configuration-dashboards-pilot-dashboard" created
configmap "istio-grafana" created
configmap "kiali" created
configmap "prometheus" created
configmap "istio-security-custom-resources" created
configmap "istio" created
configmap "istio-sidecar-injector" created
serviceaccount "istio-galley-service-account" created
serviceaccount "istio-egressgateway-service-account" created
serviceaccount "istio-ingressgateway-service-account" created
serviceaccount "istio-grafana-post-install-account" created
clusterrole.rbac.authorization.k8s.io "istio-grafana-post-install-istio-system" created
clusterrolebinding.rbac.authorization.k8s.io "istio-grafana-post-install-role-binding-istio-system" created
job.batch "istio-grafana-post-install-1.1.0-snapshot.5" created
serviceaccount "kiali-service-account" created
serviceaccount "istio-mixer-service-account" created
serviceaccount "istio-pilot-service-account" created
serviceaccount "prometheus" created
serviceaccount "istio-cleanup-secrets-service-account" created
clusterrole.rbac.authorization.k8s.io "istio-cleanup-secrets-istio-system" created
clusterrolebinding.rbac.authorization.k8s.io "istio-cleanup-secrets-istio-system" created
job.batch "istio-cleanup-secrets-1.1.0-snapshot.5" created
serviceaccount "istio-security-post-install-account" created
clusterrole.rbac.authorization.k8s.io "istio-security-post-install-istio-system" created
clusterrolebinding.rbac.authorization.k8s.io "istio-security-post-install-role-binding-istio-system" created
job.batch "istio-security-post-install-1.1.0-snapshot.5" created
serviceaccount "istio-citadel-service-account" created
serviceaccount "istio-sidecar-injector-service-account" created
clusterrole.rbac.authorization.k8s.io "istio-galley-istio-system" created
clusterrole.rbac.authorization.k8s.io "istio-egressgateway-istio-system" created
clusterrole.rbac.authorization.k8s.io "istio-ingressgateway-istio-system" created
clusterrole.rbac.authorization.k8s.io "kiali" created
clusterrole.rbac.authorization.k8s.io "istio-mixer-istio-system" created
clusterrole.rbac.authorization.k8s.io "istio-pilot-istio-system" created
clusterrole.rbac.authorization.k8s.io "prometheus-istio-system" created
clusterrole.rbac.authorization.k8s.io "istio-citadel-istio-system" created
clusterrole.rbac.authorization.k8s.io "istio-sidecar-injector-istio-system" created
clusterrolebinding.rbac.authorization.k8s.io "istio-galley-admin-role-binding-istio-system" created
clusterrolebinding.rbac.authorization.k8s.io "istio-egressgateway-istio-system" created
clusterrolebinding.rbac.authorization.k8s.io "istio-ingressgateway-istio-system" created
clusterrolebinding.rbac.authorization.k8s.io "istio-kiali-admin-role-binding-istio-system" created
clusterrolebinding.rbac.authorization.k8s.io "istio-mixer-admin-role-binding-istio-system" created
clusterrolebinding.rbac.authorization.k8s.io "istio-pilot-istio-system" created
clusterrolebinding.rbac.authorization.k8s.io "prometheus-istio-system" created
clusterrolebinding.rbac.authorization.k8s.io "istio-citadel-istio-system" created
clusterrolebinding.rbac.authorization.k8s.io "istio-sidecar-injector-admin-role-binding-istio-system" created
role.rbac.authorization.k8s.io "istio-ingressgateway-sds" created
rolebinding.rbac.authorization.k8s.io "istio-ingressgateway-sds" created
service "istio-galley" created
service "istio-egressgateway" created
service "istio-ingressgateway" created
service "grafana" created
service "kiali" created
service "istio-policy" created
service "istio-telemetry" created
service "istio-pilot" created
service "prometheus" created
service "istio-citadel" created
service "servicegraph" created
service "istio-sidecar-injector" created
deployment.extensions "istio-galley" created
deployment.extensions "istio-egressgateway" created
deployment.extensions "istio-ingressgateway" created
deployment.extensions "grafana" created
deployment.extensions "kiali" created
deployment.extensions "istio-policy" created
deployment.extensions "istio-telemetry" created
deployment.extensions "istio-pilot" created
deployment.extensions "prometheus" created
deployment.extensions "istio-citadel" created
deployment.extensions "servicegraph" created
deployment.extensions "istio-sidecar-injector" created
deployment.extensions "istio-tracing" created
horizontalpodautoscaler.autoscaling "istio-egressgateway" created
horizontalpodautoscaler.autoscaling "istio-ingressgateway" created
horizontalpodautoscaler.autoscaling "istio-policy" created
horizontalpodautoscaler.autoscaling "istio-telemetry" created
horizontalpodautoscaler.autoscaling "istio-pilot" created
service "jaeger-query" created
service "jaeger-collector" created
service "jaeger-agent" created
service "zipkin" created
service "tracing" created
mutatingwebhookconfiguration.admissionregistration.k8s.io "istio-sidecar-injector" created
poddisruptionbudget.policy "istio-galley" created
poddisruptionbudget.policy "istio-egressgateway" created
poddisruptionbudget.policy "istio-ingressgateway" created
poddisruptionbudget.policy "istio-policy" created
poddisruptionbudget.policy "istio-telemetry" created
poddisruptionbudget.policy "istio-pilot" created
unable to recognize "install/kubernetes/istio-demo.yaml": no matches for kind "attributemanifest" in version "config.istio.io/v1alpha2"
unable to recognize "install/kubernetes/istio-demo.yaml": no matches for kind "attributemanifest" in version "config.istio.io/v1alpha2"
unable to recognize "install/kubernetes/istio-demo.yaml": no matches for kind "handler" in version "config.istio.io/v1alpha2"
unable to recognize "install/kubernetes/istio-demo.yaml": no matches for kind "logentry" in version "config.istio.io/v1alpha2"
unable to recognize "install/kubernetes/istio-demo.yaml": no matches for kind "logentry" in version "config.istio.io/v1alpha2"
unable to recognize "install/kubernetes/istio-demo.yaml": no matches for kind "rule" in version "config.istio.io/v1alpha2"
unable to recognize "install/kubernetes/istio-demo.yaml": no matches for kind "rule" in version "config.istio.io/v1alpha2"
unable to recognize "install/kubernetes/istio-demo.yaml": no matches for kind "metric" in version "config.istio.io/v1alpha2"
unable to recognize "install/kubernetes/istio-demo.yaml": no matches for kind "metric" in version "config.istio.io/v1alpha2"
unable to recognize "install/kubernetes/istio-demo.yaml": no matches for kind "metric" in version "config.istio.io/v1alpha2"
unable to recognize "install/kubernetes/istio-demo.yaml": no matches for kind "metric" in version "config.istio.io/v1alpha2"
unable to recognize "install/kubernetes/istio-demo.yaml": no matches for kind "metric" in version "config.istio.io/v1alpha2"
unable to recognize "install/kubernetes/istio-demo.yaml": no matches for kind "metric" in version "config.istio.io/v1alpha2"
unable to recognize "install/kubernetes/istio-demo.yaml": no matches for kind "metric" in version "config.istio.io/v1alpha2"
unable to recognize "install/kubernetes/istio-demo.yaml": no matches for kind "metric" in version "config.istio.io/v1alpha2"
unable to recognize "install/kubernetes/istio-demo.yaml": no matches for kind "handler" in version "config.istio.io/v1alpha2"
unable to recognize "install/kubernetes/istio-demo.yaml": no matches for kind "rule" in version "config.istio.io/v1alpha2"
unable to recognize "install/kubernetes/istio-demo.yaml": no matches for kind "rule" in version "config.istio.io/v1alpha2"
unable to recognize "install/kubernetes/istio-demo.yaml": no matches for kind "rule" in version "config.istio.io/v1alpha2"
unable to recognize "install/kubernetes/istio-demo.yaml": no matches for kind "rule" in version "config.istio.io/v1alpha2"
unable to recognize "install/kubernetes/istio-demo.yaml": no matches for kind "handler" in version "config.istio.io/v1alpha2"
unable to recognize "install/kubernetes/istio-demo.yaml": no matches for kind "rule" in version "config.istio.io/v1alpha2"
unable to recognize "install/kubernetes/istio-demo.yaml": no matches for kind "rule" in version "config.istio.io/v1alpha2"
unable to recognize "install/kubernetes/istio-demo.yaml": no matches for kind "kubernetes" in version "config.istio.io/v1alpha2"
unable to recognize "install/kubernetes/istio-demo.yaml": no matches for kind "DestinationRule" in version "networking.istio.io/v1alpha3"
unable to recognize "install/kubernetes/istio-demo.yaml": no matches for kind "DestinationRule" in version "networking.istio.io/v1alpha3"

5   运行  kubectl get pods -n istio-system -w  查看pod状态

NAME                                                 READY     STATUS                       RESTARTS   AGE
grafana-f8467cc6-lkrfq / Running 7m
istio-citadel-676c58584b-drnnm / Running 7m
istio-cleanup-secrets-1.1.-snapshot.-hhwbl / Completed 7m
istio-egressgateway-54477c6569-gk5bj / Running 7m
istio-galley-58b7c6b6bb-8sqc2 / Running 7m
istio-grafana-post-install-1.1.-snapshot.-655cz / Completed 7m
istio-ingressgateway-f6c4b779b-g8cpd / Running 7m
istio-pilot-595d5949f8-rlv8f / Running 7m
istio-policy-755cf49c4f-xwm64 / Running 7m
istio-security-post-install-1.1.-snapshot.-x6c6z / Completed 7m
istio-sidecar-injector-6d7586f8cd-pntbg / Running 7m
istio-telemetry-7c7ff645cf-dhk7w / Running 7m
istio-tracing-6849759bc8-mhjjs / Running 7m
kiali-7766b75767-p6ws6 / CreateContainerConfigError 7m
prometheus-849b9cddff-xf4f4 / Running 7m
servicegraph-655755f6c9-s7qtr / Running 7m

  6 部署两个版本的服务

       (服务的项目地址: https://github.com/fleeto/flaskapp

  flask.istio.yaml:

apiVersion: v1
kind: Service
metadata:
name: flaskapp
labels:
app: flaskapp
spec:
selector:
app: flaskapp
ports:
- name: http
port:
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: flaskapp-v1
spec:
replicas:
template:
metadata:
labels:
app: flaskapp
version: v1
spec:
containers:
- name: flaskapp
image: dustise/flaskapp
imagePullPolicy: Always
env:
- name: version
value: v1
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: flaskapp-v2
spec:
replicas:
template:
metadata:
labels:
app: flaskapp
version: v2
spec:
containers:
- name: flaskapp
image: dustise/flaskapp
imagePullPolicy: Always
env:
- name: version
value: v2
XXXXXXXXXXXXXX:~$ istioctl kube-inject -f flask.istio.yaml | kubectl apply -f - service "flaskapp" created deployment.extensions "flaskapp-v1" created deployment.extensions "flaskapp-v2" created

运行上面的命令,用istioctl kube-inject进行注入: 这个命令的作用是: 修改kubernetes Deployment, 在Pod中注入在前面提到的Sidecar容器,然后再用管道命令输出给kubectl, 提交到K8s集群。

~$ kubectl get pods
NAME READY STATUS RESTARTS AGE
flaskapp-v1-d94f5cd8d-7lbbf / Running 10m
flaskapp-v2-86dfb8d97f-s9hgq / Running 10m

查看Pod详情:

XXXXXXXXXXXXXX:~$ kubectl describe po flaskapp-v1-d94f5cd8d-7lbbf
Name:           flaskapp-v1-d94f5cd8d-7lbbf
Namespace: default
Node: galaxykubernetes01/9.37.138.215
Start Time: Fri, Feb :: -
Labels: app=flaskapp
pod-template-hash=
version=v1
Annotations: sidecar.istio.io/status={"version":"84d7067e1bc34e8101e25667c84926d857e8d6ca3873a5dfd78345f405087030","initContainers":["istio-init"],"containers":["istio-proxy"],"volumes":["istio-envoy","istio-certs...
Status: Running
IP: 10.244.4.174
Controlled By: ReplicaSet/flaskapp-v1-d94f5cd8d
Init Containers:
istio-init:
Container ID: docker://cbb03a144c2a4d68b5d8a60562750073bdde9f59558b1c654d9348e8c5ab2b4d
Image: docker.io/istio/proxy_init:1.1.-snapshot.
Image ID: docker-pullable://istio/proxy_init@sha256:817dde540690a8ead6f24acc1dfbef3b9cc18996943983d6688b510b8ccf1c77
Port: <none>
Host Port: <none>
Args:
-p -u -m
REDIRECT
-i
*
-x -b -d State: Terminated
Reason: Completed
Exit Code:
Started: Fri, Feb :: -
Finished: Fri, Feb :: -
Ready: True
Restart Count:
Limits:
cpu: 10m
memory: 10Mi
Requests:
cpu: 10m
memory: 10Mi
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-qjj5t (ro)
Containers:
flaskapp:
Container ID: docker://2e037f2213d58d2de0a4e3f7bd5e9b64fe30f8be41c1e15612d1308ee00aa50b
Image: dustise/flaskapp
Image ID: docker-pullable://dustise/flaskapp@sha256:fe21074376c36bb86358135f82c35ad40be99698ebd3cf277cbda1044308a255
Port: <none>
Host Port: <none>
State: Running
Started: Fri, Feb :: -
Ready: True
Restart Count:
Environment:
version: v1
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-qjj5t (ro)
istio-proxy:
Container ID: docker://7935bf3e9599a330d19deaea242dbd58e941e72b02d9d02010cc001d1a4f3558
Image: docker.io/istio/proxyv2:1.1.-snapshot.
Image ID: docker-pullable://istio/proxyv2@sha256:2329bed32fde5d3ed0c4d3f7f0594e8258573226c50406e7d25d0298cd119685
Port: /TCP
Host Port: /TCP
Args:
proxy
sidecar
--domain
$(POD_NAMESPACE).svc.cluster.local
--configPath
/etc/istio/proxy
--binaryPath
/usr/local/bin/envoy
--serviceCluster
flaskapp.default
--drainDuration
45s
--parentShutdownDuration
1m0s
--discoveryAddress
istio-pilot.istio-system:
--zipkinAddress
zipkin.istio-system:
--connectTimeout
10s
--proxyAdminPort --controlPlaneAuthPolicy
NONE
--statusPort --applicationPorts State: Running
Started: Fri, Feb :: -
Ready: True
Restart Count:
Requests:
cpu: 10m
Readiness: http-get http://:15020/healthz/ready delay=1s timeout=1s period=2s #success=1 #failure=30
Environment:
POD_NAME: flaskapp-v1-d94f5cd8d-7lbbf (v1:metadata.name)
POD_NAMESPACE: default (v1:metadata.namespace)
INSTANCE_IP: (v1:status.podIP)
ISTIO_META_POD_NAME: flaskapp-v1-d94f5cd8d-7lbbf (v1:metadata.name)
ISTIO_META_CONFIG_NAMESPACE: default (v1:metadata.namespace)
ISTIO_META_INTERCEPTION_MODE: REDIRECT
ISTIO_METAJSON_LABELS: {"app":"flaskapp","version":"v1"} Mounts:
/etc/certs/ from istio-certs (ro)
/etc/istio/proxy from istio-envoy (rw)
/var/run/secrets/kubernetes.io/serviceaccount from default-token-qjj5t (ro)
Conditions:
Type Status
Initialized True
Ready True
PodScheduled True
Volumes:
istio-envoy:
Type: EmptyDir (a temporary directory that shares a pod's lifetime)
Medium: Memory
istio-certs:
Type: Secret (a volume populated by a Secret)
SecretName: istio.default
Optional: true
default-token-qjj5t:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-qjj5t
Optional: false
QoS Class: Burstable
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 11m default-scheduler Successfully assigned flaskapp-v1-d94f5cd8d-7lbbf to galaxykubernetes01
Normal SuccessfulMountVolume 11m kubelet, galaxykubernetes01 MountVolume.SetUp succeeded for volume "istio-envoy"
Normal SuccessfulMountVolume 11m kubelet, galaxykubernetes01 MountVolume.SetUp succeeded for volume "default-token-qjj5t"
Normal SuccessfulMountVolume 11m kubelet, galaxykubernetes01 MountVolume.SetUp succeeded for volume "istio-certs"
Normal Pulling 11m kubelet, galaxykubernetes01 pulling image "docker.io/istio/proxy_init:1.1.0-snapshot.5"
Normal Pulled 11m kubelet, galaxykubernetes01 Successfully pulled image "docker.io/istio/proxy_init:1.1.0-snapshot.5"
Normal Created 11m kubelet, galaxykubernetes01 Created container
Normal Started 11m kubelet, galaxykubernetes01 Started container
Normal Pulling 11m kubelet, galaxykubernetes01 pulling image "dustise/flaskapp"
Normal Pulled 11m kubelet, galaxykubernetes01 Successfully pulled image "dustise/flaskapp"
Normal Created 11m kubelet, galaxykubernetes01 Created container
Normal Started 11m kubelet, galaxykubernetes01 Started container
Normal Pulling 11m kubelet, galaxykubernetes01 pulling image "docker.io/istio/proxyv2:1.1.0-snapshot.5"
Normal Pulled 10m kubelet, galaxykubernetes01 Successfully pulled image "docker.io/istio/proxyv2:1.1.0-snapshot.5"
Normal Created 10m kubelet, galaxykubernetes01 Created container
Normal Started 10m kubelet, galaxykubernetes01 Started container

从上面的详情看出,在这个Pod中多了一个容器, 名称是 istio-proxy, 这就是注入的结果。另外还有一个名是 istio-init的初始化容器,这个容器是用于初始化劫持的。

  4.4 部署客户端服务

    (客户端项目地址: https://github.com/fleeto/flaskapp)

apiVersion: v1
kind: Service
metadata:
name: sleep
labels:
app: sleep
spec:
selector:
app: sleep
ports:
- name: ssh
port:
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: sleep-v1
spec:
replicas:
template:
metadata:
labels:
app: sleep
version: v1
spec:
containers:
- name: sleep
image: dustise/sleep
imagePullPolicy: Always
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: sleep-v2
spec:
replicas:
template:
metadata:
labels:
app: sleep
version: v2
spec:
containers:
- name: sleep
image: dustise/sleep
imagePullPolicy: Always

  没有service的Deployment是无法被Istio发现并进行操作的。

  同样,对该文件进行注入,并提交到K8s上运行:

XXXXXXXXXXXXXX:~$ istioctl kube-inject -f sleep.yaml | kubectl apply -f -
service "sleep" created
deployment.extensions "sleep-v1" created
deployment.extensions "sleep-v2" created

  4.5 验证服务

  通过kubectl exec -it 命令进入客户端Pod, 来测试flaskapp服务的具体表现。

XXXXXXXXXXXXXX:~$ kubectl get po

NAME READY STATUS RESTARTS AGE
flaskapp-v1-d94f5cd8d-7lbbf 2/2 Running 0 17h
flaskapp-v2-86dfb8d97f-s9hgq 2/2 Running 0 17h
sleep-v1-5f6946dcf8-sf94h 2/2 Running 0 1m
sleep-v2-bbb4cc688-bwm7q 2/2 Running 0 1m
kubeusr@GalaxyKubernetesMaster:~$ kubectl exec -it sleep-v1-5f6946dcf8-sf94h -c sleep bash

bash-4.4# for i in `seq 10`;do http --body http://flaskapp/env/version;done  (进行10次调用)
v1

v2

v1

v1

v2

v1

v2

v1

v2

v1

从上面的结果可以看出,v2和v1两种结果随机出现,大约各占一半。

  4.6 创建目标规则和默认路由

  接下来使用Istio来管理这两个服务的流量。

  定义一个名称为flaskapp的DestinationRule,它利用Pod标签把flaskapp服务分成两个subset, 分别命名为v1和v2.

apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: flaskapp
spec:
host: flaskapp
subsets:
- name: v1
labels:
version: v1
- name: v2
labels:
version: v2

XXXXXXXXXXXXXXXXXX:~$  kubectl apply -f flaskapp-destinationrule.yaml     # 部署到集群上

destinationrule.networking.istio.io "flaskapp" created

  接下来,为flaskapp服务创建默认的路由规则,不论是否进行进一步的流量控制,都建议为网格中的服务创建默认的路由规则,以防止发生意料之外的路由规则。

  定义一个VirtualService对象,它负责接管对 “flaskapp”这一主机名的访问,将流量都转发到DestinationRule定义的v2 subset上。

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: flaskapp-default-v2
spec:
hosts:
- flaskapp
http:
- route:
- destination:
host: flaskapp
subset: v2
XXXXXXXXXXXXXXXXXXX:~$ kubectl apply -f flaskapp-default-vs-v2.yaml
virtualservice.networking.istio.io "flaskapp-default-v2" created

再次进入客户端Pod, 看看新定义的流量管理规则是否生效

XXXXXXXXXXXXXXXXX:~$ kubectl exec -it sleep-v1-5f6946dcf8-sf94h -c sleep bash
bash-4.4# for i in `seq `;do http --body http://flaskapp/env/version;done
v2
v2
v2
v2
v2
v2
v2
v2
v2
v2

  

第四章 istio快速入门(快速安装)的更多相关文章

  1. webpack快速入门——如何安装webpack及注意事项

    1.window+R键,输入cmd打开命令行工具,输入 mkdir XXXX(XX:文件夹名): 2.cd XXX 进入刚刚创建好的文件夹里,输入cnpm install -g webpack (安装 ...

  2. Redis快速入门:安装、配置和操作

    本文是有关Redis的系列技术文章之一.在之前的文章中介绍了<Redis快速入门:初识Redis>,对Redis有了一个初步的了解.今天继续为大家介绍Redis如何安装.配置和操作. 系列 ...

  3. (1)Maven快速入门_1maven安装

    Maven 快速入门 1.1 Maven官网下载     windows 系统 下载 下图红色框选处. 下载到本地解压, 创建一个本地maven仓库的目录 maven_lib 配置Maven的环境变量 ...

  4. 第四章:Python基础の快速认识內置函数和操作实战

    本課主題 內置函数介紹和操作实战 装饰器介紹和操作实战 本周作业 內置函数介紹和操作实战 返回Boolean值的內置函数 all( ): 接受一個可以被迭代的對象,如果函数裡所有為真,才會真:有一個是 ...

  5. maven快速入门之安装

    maven是基于项目对象模型(pom) 可以通过y一小段描述信息来管理项目的构建,报告,和文档的软件项目管理工具. 覆盖编译,测试运行清理构建周期,提供仓库的概念,统一帮助管理项目. 下载:http: ...

  6. 《精通C#》十四章-.NET程序集入门

    在书中,这一章节的开头说的是自定义命名空间和使用命名空间,在以我目前有限的经验来说,程序集就是一个类库经过编译之后,所生成的一个在引用命名空间,进而使用该文件中已经定义好的字段,属性以及方法的文件,以 ...

  7. docker安装kafka快速入门

    docker安装kafka快速入门 1.安装zookeeper docker search zookeeperdocker pull zookeeperdocker run -d -v /home/s ...

  8. webpack快速入门——打包后如何调试

    在配置devtool时,webpack给我们提供了四种选项. source-map:在一个单独文件中产生一个完整且功能完全的文件.这个文件具有最好的source map,但是它会减慢打包速度: che ...

  9. 【干货合集】Docker快速入门与进阶

    收录待用,修改转载已取得腾讯云授权 Docker 在众多技术中,绝对是当红炸子鸡.这年头,如果你不懂一点容器,不学一些Docker,还怎么出去跟人炫耀技术? Docker 也是云计算技术中较为热门的一 ...

随机推荐

  1. java中a++和++a的区别详解

    java中的++操作无论在前还是在后,都是在变量自身的值加1,接下来将具体描述两者的区别 int a =5; int b =a++; System.out.println(b); 1.通俗易懂的理解是 ...

  2. ffmpeg jpeg图片播放失败之问题排查

    播放jpeg时,avformat_find_stream_info出现以下问题,排查: [jpeg_pipe @ 0x146a80] Could not find codec parameters f ...

  3. EasyPlayer RTSP Android安卓播放器修复播放画面卡在第一帧bug

    本文转自EasyDarwin团队成员John的博客:http://blog.csdn.net/jyt0551/article/details/75717097 最近发现某些手机在运行EasyPlaye ...

  4. 【排序】快速排序,C++实现

    原创博文,转载请注明出处! 本文代码的github地址 # 基本思想 ”快速排序“是对”冒泡排序“的改进. 基本原理:基于分治法,在待排线性表中取一个元素pivot作为枢轴值,通过一趟排序将待排线性表 ...

  5. jQuery radio|checkbox的取值与赋值

    文章简单即是美[我说的是技术博客] |--radio   |--checkbox   参考: http://blog.csdn.net/gd2008/article/details/6951208 h ...

  6. BZOJ4543 POI2014 Hotel加强版 【长链剖分】【DP】*

    BZOJ4543 POI2014 Hotel加强版 Description 同OJ3522 数据范围:n<=100000 Sample Input 7 1 2 5 7 2 5 2 3 5 6 4 ...

  7. IOS UIView 放大缩小

    /创建缩小了的视图myWeiBoImageVC = [[UIViewController alloc] init];myWeiBoImageVC.view.clipsToBounds = YES;my ...

  8. 《DSP using MATLAB》示例Example7.10

    代码: ws1 = 0.2*pi; wp1 = 0.35*pi; wp2 = 0.65*pi; ws2 = 0.8*pi; As = 60; tr_width = min((wp1-ws1), (ws ...

  9. Linux下Apache服务器配置

    Linux下Apache服务器配置 相关包: httpd-2.2.3-29.e15.i386.rpm                 //主程序包 httpd-devel-2.2.3-29.e15.i ...

  10. 使用C#和Java发送邮件(转载)

    using System.Net.Mail; using System.Net; public class EmailEntity { private MailMessage mm; /// < ...