第四章 istio快速入门(快速安装)
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快速入门(快速安装)的更多相关文章
- webpack快速入门——如何安装webpack及注意事项
1.window+R键,输入cmd打开命令行工具,输入 mkdir XXXX(XX:文件夹名): 2.cd XXX 进入刚刚创建好的文件夹里,输入cnpm install -g webpack (安装 ...
- Redis快速入门:安装、配置和操作
本文是有关Redis的系列技术文章之一.在之前的文章中介绍了<Redis快速入门:初识Redis>,对Redis有了一个初步的了解.今天继续为大家介绍Redis如何安装.配置和操作. 系列 ...
- (1)Maven快速入门_1maven安装
Maven 快速入门 1.1 Maven官网下载 windows 系统 下载 下图红色框选处. 下载到本地解压, 创建一个本地maven仓库的目录 maven_lib 配置Maven的环境变量 ...
- 第四章:Python基础の快速认识內置函数和操作实战
本課主題 內置函数介紹和操作实战 装饰器介紹和操作实战 本周作业 內置函数介紹和操作实战 返回Boolean值的內置函数 all( ): 接受一個可以被迭代的對象,如果函数裡所有為真,才會真:有一個是 ...
- maven快速入门之安装
maven是基于项目对象模型(pom) 可以通过y一小段描述信息来管理项目的构建,报告,和文档的软件项目管理工具. 覆盖编译,测试运行清理构建周期,提供仓库的概念,统一帮助管理项目. 下载:http: ...
- 《精通C#》十四章-.NET程序集入门
在书中,这一章节的开头说的是自定义命名空间和使用命名空间,在以我目前有限的经验来说,程序集就是一个类库经过编译之后,所生成的一个在引用命名空间,进而使用该文件中已经定义好的字段,属性以及方法的文件,以 ...
- docker安装kafka快速入门
docker安装kafka快速入门 1.安装zookeeper docker search zookeeperdocker pull zookeeperdocker run -d -v /home/s ...
- webpack快速入门——打包后如何调试
在配置devtool时,webpack给我们提供了四种选项. source-map:在一个单独文件中产生一个完整且功能完全的文件.这个文件具有最好的source map,但是它会减慢打包速度: che ...
- 【干货合集】Docker快速入门与进阶
收录待用,修改转载已取得腾讯云授权 Docker 在众多技术中,绝对是当红炸子鸡.这年头,如果你不懂一点容器,不学一些Docker,还怎么出去跟人炫耀技术? Docker 也是云计算技术中较为热门的一 ...
随机推荐
- chrome浏览器Uncaught TypeError: object is not a function问题解决
今天测试多浏览器的时候,chrome浏览器出现Uncaught TypeError: object is not a function: 解决办法:(不知道为啥子)改一下js的方法名字就可以了
- L154
Several possessions of the late physicist's Stephen Hawking will be included in an upcoming auction ...
- [知识图谱] 环境配置:Java8 + Maven3 + HBase + Titan
1.Java Java8安装配置 2.Maven Linux下的Maven安装与配置 3.Hbase 官方安装教程:http://s3.thinkaurelius.com/docs/titan/1.0 ...
- 密钥库文件格式[keystore]代码
密钥库文件格式[keystore]代码 格式 : JKS 扩展名 : .jks/.ks 描述 : [Java Keystore]密钥库的Java实现版本,pro ...
- iOS-----GitHub上比较齐全的iOS 工具和App
Github-iOS 工具 和 App 系统基础库 Category/Util sstoolkit 一套Category类型的库,附带很多自定义控件 功能不错- BFKit 又一套Ca ...
- caffe学习3——layers
1 layer是模型的本质,是计算的基本单元.Layers convolve filters, pool, take inner products, apply nonlinearities like ...
- GitLab+Rancher实践DevOps【转载】
摘要 本文描述使用自建GitLab和Rancher实践持续集成/持续交付流水线的过程,并用Rancher实现容器编排和蓝绿发布. GitLab持续集成 GitLab持续集成/持续交付流程图:部署Git ...
- 【导航】JennyHui没有宏大的计划,只有坚持!坚持!
学英语 口语 Bingo口语笔记 听力 VOA 词汇 生词积累 座右铭 随手记 TED X - > 笔记 JennyHui要成为程序猿(加油!!菜鸟终会成为大牛的!!) 后端知识 Python ...
- Ubuntu12.04中在桌面建立指向网页的链接文件的方法
#cd /usr/share/applications #cp firefox.desktop ~/Desktop #cd ~/Desktop #chmod +x firefox.desktop 右键 ...
- erl_0021 erlang和java的内存模型比较(引用)
原文 http://deepinmind.iteye.com/blog/2030390 我读到一篇相当相当有趣的关于Erlang VM内存管理策略的文章.它是Jesper Wilhelmsson写的 ...