• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

k8s笔记11

武飞扬头像
空管运维mi
帮助1

摘要:

Kubernetes aliases;omping-istio;vs-dr;

1、Kubernetes 命令使用别名可以使得在处理 Kubernetes 命令时更加简便高效。(https://mp.weixin.qq.com/s/c9PXkGkt7LIdy63KVesiTA

vim /root/.bashrc
alias kpod='kubectl get pods -A'
alias knode='kubectl get nodes'
alias kdesp='kubectl describe pod'
alias kdp='kubectl delete pod'
alias kgd='kubectl get deployments'
alias kbook='kubectl -n bookinfo'
alias ks='kubectl -n study'
curl 安装Oh My Zsh 
# yum install zsh
# sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

2、omping测试(istio)。

  • 现象1:omping的local address必须是Pod的IP,当第一次进入容器测试Pod中远端使用service IP和service名称,单播正常时,远端使用Pod的IP不行,提示“server told us to stop”。
pod/omping-a-84c4b9689b-7fsnf    172.27.29.133    k8s-node07  
pod/omping-b-69684f6589-j9gjn    172.19.199.183   k8s-node08
service/svc-omping-a   ClusterIP   10.16.121.251 50001/UDP   app=omping-a
service/svc-omping-b   ClusterIP   10.16.165.245 50001/UDP   app=omping-b
#k -n bookinfo exec -ti omping-a-84c4b9689b-7fsnf -c omping-a -- bash
root@omping-a-84c4b9689b-7fsnf:/# omping -m 225.1.0.10 -p 50001 172.27.29.133    10.16.121.251  10.16.165.245
10.16.121.251 : waiting for response msg
10.16.121.251 : server told us to stop
10.16.165.245 : waiting for response msg
10.16.165.245 : joined (S,G) = (*, 225.1.0.10), pinging
10.16.165.245 :   unicast, seq=1, size=69 bytes, dist=2, time=0.466ms
10.16.165.245 :   unicast, xmt/rcv/%loss = 8/8/0%, min/avg/max/std-dev = 0.439/0.520/0.678/0.081
10.16.165.245 : multicast, xmt/rcv/%loss = 8/0/100%, min/avg/max/std-dev = 0.000/0.000/0.000/0.000
#  k -n bookinfo exec -ti omping-b-69684f6589-j9gjn -c omping-b -- bash
root@omping-b-69684f6589-j9gjn:/# omping -m 225.1.0.10 -p 50001 172.19.199.183   10.16.121.251  10.16.165.245
10.16.121.251 : waiting for response msg
10.16.165.245 : server told us to stop
10.16.121.251 : joined (S,G) = (*, 225.1.0.10), pinging
10.16.121.251 :   unicast, seq=9, size=69 bytes, dist=2, time=0.588ms
10.16.121.251 :   unicast, xmt/rcv/%loss = 9/9/0%, min/avg/max/std-dev = 0.330/0.551/0.663/0.101
10.16.121.251 : multicast, xmt/rcv/%loss = 9/0/100%, min/avg/max/std-dev = 0.000/0.000/0.000/0.000
  • 现象2:当偶尔(条件不清楚)出现omping远端使用Pod的IP单播正常时,远端使用service IP和service名称不行,提示“server told us to stop”

3、通过HTTP重写可以在将请求转发给目标服务前修改HTTP请求中指定部分的内容,不同于重定向,用户是可见,HTTP重写对用户是不可见的,因为是在服务端进行的。(istio镜像cnblogs.com

alias kbook='kubectl -n bookinfo'
[root@k8s-master01 ~]# kbook get pod,svc,vs
NAME                                  READY   STATUS    RESTARTS   AGE
pod/httpbin-v1-65485cf4b6-zq99d       2/2     Running   0          17h
pod/httpbin-v2-85569ccfc7-6zv5d       2/2     Running   0          17h
NAME                   TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)     AGE
service/httpbin        ClusterIP   10.16.63.93     <none>        8080/TCP    17h
NAME                                          GATEWAYS               HOSTS                                   AGE
virtualservice.networking.istio.io/bookinfo   ["bookinfo-gateway"]   ["book.atc.com","book.harbor.domain"]   292d
virtualservice.networking.istio.io/httpbin    ["bookinfo-gateway"]   ["book.atc.com"]                        15h
#  k apply -f vs-v1v2-curl.yaml 
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: httpbin
  namespace: bookinfo  
spec:
  gateways:
  - bookinfo-gateway
  hosts:
    - book.atc.com  
  http:
  - match:
    - uri:
        exact: /bin  
    rewrite:                                     
      uri: "/"    
//必须加rewrite,否者IE输入http://book.atc.com:30933/bin访问失败“Not Found The quested URL was not found on the server. If you entered the URL manually please check your spelling and try again.”
    route:
    - destination:
        host: httpbin.bookinfo.svc.cluster.local
        port:
          number: 8080

4、 Istio virtual service按百分比来分配流量。

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: httpbin-v1v2
  namespace: bookinfo    
spec:
  hosts:
    - httpbin
  http:
  - route:
    - destination:
        host: httpbin
        subset: v1
      weight: 90
    - destination:
        host: httpbin
        subset: v2
      weight: 10
  • 通过客户端测试,客户端必须经过 Istio 注入,因为只有客户端被 Istio 注入才可以接收到来自 Pilot 有关 Virtual Service  和 Destination Rule 的配置信息,才可以保证流量接管生效。
alias kbook='kubectl -n bookinfo'
# export SLEEP_POD=$(kbook get pod -l app=sleep -o jsonpath={.items..metadata.name})
# kbook exec -ti  "${SLEEP_POD}" -c sleep -- sh -c 'curl http://httpbin:8080/headers' | python -m json.tool
[root@k8s-master01 ~]# kbook exec -ti curl-sleep-554d688fc4-xr4jf -c sleep  -- sh -c 'curl http://httpbin:8080/headers' | python -m json.tool
  • 也可以通过http://book.atc.com:30933/bin测试流量分配,因为参见第3项使用gateways: - bookinfo-gateway,也可以接管
    流量。
  • 但是使用http://192.168.31.211:31382/ 即将svc:httpbin的TYPE改成NodePort,不能测试自定义流量分配(实际使用k8s service只能实现最基本的流量负载均衡转发),因为NodePort不能接管流量。
[root@k8s-master01 istio]# kbook get svc
NAME           TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
httpbin        NodePort    10.16.63.93     <none>        8080:31382/TCP   19h

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhibbjab
系列文章
更多 icon
同类精品
更多 icon
继续加载