{"id":15777619,"url":"https://github.com/v5tech/k3s-istio-lab","last_synced_at":"2025-03-14T08:30:27.532Z","repository":{"id":149461732,"uuid":"458799007","full_name":"v5tech/k3s-istio-lab","owner":"v5tech","description":"搭建k3s集群和istio环境","archived":false,"fork":false,"pushed_at":"2022-05-02T11:01:23.000Z","size":15,"stargazers_count":4,"open_issues_count":0,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-11T18:05:01.228Z","etag":null,"topics":["istio","istio-bookinfo","k3s-cluster","kubernetes","kubernetes-cluster","vagrant","vagrant-cluster"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/v5tech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2022-02-13T12:12:22.000Z","updated_at":"2024-06-29T04:01:34.000Z","dependencies_parsed_at":"2023-05-16T11:45:50.010Z","dependency_job_id":null,"html_url":"https://github.com/v5tech/k3s-istio-lab","commit_stats":null,"previous_names":["v5tech/k3s-istio-lab"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/v5tech%2Fk3s-istio-lab","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/v5tech%2Fk3s-istio-lab/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/v5tech%2Fk3s-istio-lab/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/v5tech%2Fk3s-istio-lab/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/v5tech","download_url":"https://codeload.github.com/v5tech/k3s-istio-lab/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243547196,"owners_count":20308656,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["istio","istio-bookinfo","k3s-cluster","kubernetes","kubernetes-cluster","vagrant","vagrant-cluster"],"created_at":"2024-10-04T18:00:51.328Z","updated_at":"2025-03-14T08:30:27.062Z","avatar_url":"https://github.com/v5tech.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# k3s+istio\n\n搭建k3s+istio环境\n\n## 启动k3s集群\n\n```bash\nvagrant up\n```\n\n安装`kube-explorer dashboard`\n\n```bash\ncd /opt\nwget -q https://github.sfeng.workers.dev/https://github.com/cnrancher/kube-explorer/releases/download/v0.2.8/kube-explorer-linux-amd64\nmv kube-explorer-linux-amd64 kube-explorer\nchmod +x kube-explorer\ncp /etc/rancher/k3s/k3s.yaml /root/.kube/config\nIP_ADDRESS=`ip addr | grep eth1 | grep inet | awk '{print $2}' | awk -F '/' '{print $1}'`\nsed -i 's/127.0.0.1/'${IP_ADDRESS}'/' /root/.kube/config\nnohup ./kube-explorer --kubeconfig=/root/.kube/config --http-listen-port=9898 --https-listen-port=0 \u003e/dev/null 2\u003e\u00261 \u0026\n```\n\n浏览器访问 http://${IP_ADDRESS}:9898\n\n设置`Kubectl Completion Bash`\n\n```bash\nkubectl completion bash \u003e /etc/bash_completion.d/kubectl\nsource /etc/bash_completion.d/kubectl\n```\n\n## 安装istio\n\n```bash\n./install-istio.sh\n```\n\n设置`Istio Completion Bash`\n\n```bash\nistioctl completion bash \u003e /etc/bash_completion.d/istioctl\nsource /etc/bash_completion.d/istioctl\n```\n\n### istio部署bookinfo应用\n\n```bash\n# 部署示例应用\nkubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml\nkubectl get services\nkubectl get pods\nkubectl exec \"$(kubectl get pod -l app=ratings -o jsonpath='{.items[0].metadata.name}')\" -c ratings -- curl -s productpage:9080/productpage | grep -o \"\u003ctitle\u003e.*\u003c/title\u003e\"\n\n# 对外开放应用程序\nkubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml\nkubectl get gateway\nistioctl analyze\n\n# 确定入站 IP 和端口\nkubectl get svc istio-ingressgateway -n istio-system\nexport INGRESS_HOST=$(kubectl get po -l istio=ingressgateway -n istio-system -o jsonpath='{.items[0].status.hostIP}')\nexport INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name==\"http2\")].nodePort}')\nexport GATEWAY_URL=$INGRESS_HOST:$INGRESS_PORT\necho \"$GATEWAY_URL\"\n\n# 验证外部访问\necho \"http://$GATEWAY_URL/productpage\"\n\n# 应用默认目标规则\nkubectl apply -f samples/bookinfo/networking/destination-rule-all.yaml\nkubectl get destinationrules -o yaml\n\n# 查看仪表板\nkubectl apply -f samples/addons\nkubectl rollout status deployment/kiali -n istio-system\nistioctl dashboard kiali --address=0.0.0.0\nistioctl dashboard jaeger --address=0.0.0.0\nistioctl dashboard grafana --address=0.0.0.0\n\n# 清理bookinfo应用\nsamples/bookinfo/platform/kube/cleanup.sh\nkubectl get virtualservices   #-- there should be no virtual services\nkubectl get destinationrules  #-- there should be no destination rules\nkubectl get gateway           #-- there should be no gateway\nkubectl get pods              #-- the Bookinfo pods should be deleted\n```\n\n卸载istio\n\n```bash\nkubectl delete -f samples/addons\nistioctl manifest generate --set profile=demo | kubectl delete --ignore-not-found=true -f -\nkubectl delete namespace istio-system\nkubectl label namespace default istio-injection-\n```\n\n### 部署google-samples-microservices\n\nhttps://github.com/GoogleCloudPlatform/microservices-demo\n\n* k3s集群部署应用\n\n创建namespace\n\n```bash\n$ kubectl create ns google-samples-microservices\n```\n\n应用配置，部署应用\n\n```bash\n$ kubectl apply -n google-samples-microservices -f kubernetes-manifests.yaml\n\n$ kubectl get pod -n google-samples-microservices\nNAME                                     READY   STATUS    RESTARTS   AGE\nsvclb-frontend-external-2sg5q            0/1     Pending   0          2m57s\nsvclb-frontend-external-9rfq4            0/1     Pending   0          2m57s\ncheckoutservice-558b447fdc-9dnmx         1/1     Running   0          2m58s\nshippingservice-7b64ffc765-kvzfv         1/1     Running   0          2m55s\nredis-cart-78746d49dc-wbrhm              1/1     Running   0          2m55s\nproductcatalogservice-cc7c79cf5-b4wlp    1/1     Running   0          2m56s\nfrontend-8446f74795-8nghz                1/1     Running   0          2m57s\ncartservice-d7f69f549-jckfq              1/1     Running   0          2m56s\ncurrencyservice-7d5c4974b9-p5sz7         1/1     Running   0          2m56s\npaymentservice-6fd9ff5d6c-tg4cx          1/1     Running   0          2m57s\nloadgenerator-d95bc946f-j562g            1/1     Running   0          2m56s\nemailservice-f57d5c6c9-lm6xv             1/1     Running   0          2m58s\nrecommendationservice-79fd4d769c-dd6bc   1/1     Running   0          2m58s\nadservice-65d4dc6b67-pmth7               1/1     Running   0          2m55s\n\n$ kubectl get svc -n google-samples-microservices\nNAME                    TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE\nemailservice            ClusterIP      10.43.182.252   \u003cnone\u003e        5000/TCP       3m\ncheckoutservice         ClusterIP      10.43.122.110   \u003cnone\u003e        5050/TCP       3m\nrecommendationservice   ClusterIP      10.43.150.235   \u003cnone\u003e        8080/TCP       3m\nfrontend                ClusterIP      10.43.198.168   \u003cnone\u003e        80/TCP         2m59s\nfrontend-external       LoadBalancer   10.43.237.62    \u003cpending\u003e     80:30841/TCP   2m59s\npaymentservice          ClusterIP      10.43.200.157   \u003cnone\u003e        50051/TCP      2m59s\nproductcatalogservice   ClusterIP      10.43.194.205   \u003cnone\u003e        3550/TCP       2m58s\ncartservice             ClusterIP      10.43.218.17    \u003cnone\u003e        7070/TCP       2m58s\ncurrencyservice         ClusterIP      10.43.223.195   \u003cnone\u003e        7000/TCP       2m57s\nshippingservice         ClusterIP      10.43.129.253   \u003cnone\u003e        50051/TCP      2m57s\nredis-cart              ClusterIP      10.43.156.117   \u003cnone\u003e        6379/TCP       2m57s\nadservice               ClusterIP      10.43.155.192   \u003cnone\u003e        9555/TCP       2m57s\n```\n\n浏览器访问 http://192.168.56.101:30841\n\n* 为微服务启用istio\n\n```bash\nkubectl create ns istio-app\nkubectl label ns istio-app istio-injection=enabled\nkubectl apply -n istio-app -f kubernetes-manifests.yaml\nkubectl get pod -n istio-app\nkubectl delete svc frontend-external -n istio-app\nkubectl get svc -n istio-system\nkubectl apply -n istio-app -f istio-manifests.yaml\nkubectl delete serviceentry allow-egress-google-metadata -n istio-app\nkubectl delete serviceentry allow-egress-googleapis -n istio-app\n```\n\n浏览器访问 http://192.168.56.101:30792 (端口`30792`为`kubectl get svc -n istio-system`的80端口暴露出来的端口)\n\n* istio金丝雀发布\n\n```bash\nkubectl delete deploy productcatalogservice -n istio-app\n```\n\nproductcatalog-v1.yaml\n\n```yaml\napiVersion: apps/v1\nkind: Deployment\nmetadata:\n  name: productcatalogservice-v1\nspec:\n  selector:\n    matchLabels:\n      app: productcatalogservice\n  template:\n    metadata:\n      labels:\n        app: productcatalogservice\n        # 指定为 v1 版本\n        version: v1\n    spec:\n      serviceAccountName: default\n      terminationGracePeriodSeconds: 5\n      containers:\n      - name: server\n        image: docker.io/v5cn/google-samples-microservices-productcatalogservice:v0.3.6\n        ports:\n        - containerPort: 3550\n        env:\n        - name: PORT\n          value: \"3550\"\n        - name: DISABLE_STATS\n          value: \"1\"\n        - name: DISABLE_TRACING\n          value: \"1\"\n        - name: DISABLE_PROFILER\n          value: \"1\"\n        readinessProbe:\n          exec:\n            command: [\"/bin/grpc_health_probe\", \"-addr=:3550\"]\n        livenessProbe:\n          exec:\n            command: [\"/bin/grpc_health_probe\", \"-addr=:3550\"]\n        resources:\n          requests:\n            cpu: 100m\n            memory: 64Mi\n          limits:\n            cpu: 200m\n            memory: 128Mi\n```\n\n```bash\nkubectl apply -n istio-app -f productcatalog-v1.yaml\nkubectl get deploy productcatalogservice-v1 -n istio-app\n```\n\nproductcatalog-v2.yaml\n\n```yaml\napiVersion: apps/v1\nkind: Deployment\nmetadata:\n  name: productcatalogservice-v2\nspec:\n  selector:\n    matchLabels:\n      app: productcatalogservice\n  template:\n    metadata:\n      labels:\n        app: productcatalogservice\n        # 指定为 v2 版本\n        version: v2\n    spec:\n      containers:\n      - env:\n        - name: PORT\n          value: '3550'\n        - name: EXTRA_LATENCY\n          value: 3s\n        image: docker.io/v5cn/google-samples-microservices-productcatalogservice:v0.3.6\n        livenessProbe:\n          exec:\n            command:\n            - /bin/grpc_health_probe\n            - -addr=:3550\n        name: server\n        ports:\n        - containerPort: 3550\n        readinessProbe:\n          exec:\n            command:\n            - /bin/grpc_health_probe\n            - -addr=:3550\n        resources:\n          limits:\n            cpu: 200m\n            memory: 128Mi\n          requests:\n            cpu: 100m\n            memory: 64Mi\n      terminationGracePeriodSeconds: 5\n```\n\n```bash\nkubectl apply -n istio-app -f productcatalog-v2.yaml\nkubectl get deploy productcatalogservice-v2 -n istio-app\n```\n\nvs-split-traffic.yaml\n\n```yaml\napiVersion: networking.istio.io/v1alpha3\nkind: VirtualService\nmetadata:\n  name: productcatalogservice\nspec:\n  hosts:\n  - productcatalogservice\n  http:\n  - route:\n    - destination:\n        host: productcatalogservice\n        subset: v1\n      weight: 75\n    - destination:\n        host: productcatalogservice\n        subset: v2\n      weight: 25\n```\n\n```bash\nkubectl apply -n istio-app -f vs-split-traffic.yaml\n```\n\ndestinationrule.yaml\n\n```yaml\napiVersion: networking.istio.io/v1alpha3\nkind: DestinationRule\nmetadata:\n  name: productcatalogservice\nspec:\n  host: productcatalogservice\n  subsets:\n    - labels:\n        app: productcatalogservice\n        version: v1\n      name: v1\n    - labels:\n        app: productcatalogservice\n        version: v2\n      name: v2\n```\n\n```bash\nkubectl apply -n istio-app -f destinationrule.yaml\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fv5tech%2Fk3s-istio-lab","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fv5tech%2Fk3s-istio-lab","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fv5tech%2Fk3s-istio-lab/lists"}