1、CI/CD 流程被称作“软件供应链”(Software Supply Chain)。
2、对于程序来说,做到安全是日常,风险是例外(Secure by Default and Insecure by Exception);对于人类来说,做到袖手旁观是日常,主动干预是例外(Human Actions Should Be by Exception, Not Routine)。
摘自「周志明」《凤凰架构》
使用 openssl 自行签发证书,参考命令:
## 0. Enter PEM pass phrase: ********
## 1. root cert
# generate root cert, output: `privkey.pem` and `ca.pem`
openssl req -out ca.pem -new -x509 -days 3650 -subj "/C=CN/CN=root/emailAddress=jwkljh@163.com"
## this command will output two files: privkey.pem and ca.pem
## 2. server cert
# generate server private key, output: `server.key`
openssl genrsa -out server.key 2048
# generate server cert request, output: `server.req`
openssl req -key server.key -new -out server.req -subj "/C=CN/CN=istio/emailAddress=jwkljh@163.com"
# generate server cert, output: `server.crt`
openssl x509 -req -in server.req -CAkey privkey.pem -CA ca.pem -days 3650 -CAcreateserial -CAserial serial -out server.crt
# merge server cert and server private key, output: `server.pem`
cat server.key server.crt > server.pem
# verify server cert
openssl verify -CAfile ca.pem server.pem
# generate public key from private key
openssl pkey -pubout -in server.key > server_pub.key
## 3. client cert
# generate client private key, output: `client.key`
openssl genrsa -out client.key 2048
# generate client cert request, output: `client.req`
openssl req -key client.key -new -out client.req -subj "/C=CN/CN=istiocli/emailAddress=jwkljh@163.com"
# generate client cert, output: `client.crt`
openssl x509 -req -in client.req -CAkey privkey.pem -CA ca.pem -days 3650 -CAserial serial -out client.crt
# merge client cert and client private key, output: `client.pem`
cat client.key client.crt > client.pem
# verify client cert
openssl verify -CAfile ca.pem client.pem
获得 3 个证书:其中,ca.pem 作为根证书,server.pem 和 client.pem 分别作为服务端和客户端的证书。
➜ ssl-certs git:(main) ✗ ls -lrt
total 44
-rw------- 1 demon demon 1854 2月 17 14:28 privkey.pem
-rw-rw-r-- 1 demon demon 1220 2月 17 14:28 ca.pem
-rw------- 1 demon demon 1704 2月 17 14:29 server.key
-rw-rw-r-- 1 demon demon 944 2月 17 14:30 server.req
-rw-rw-r-- 1 demon demon 1099 2月 17 14:31 server.crt
-rw-rw-r-- 1 demon demon 2803 2月 17 14:32 server.pem
-rw------- 1 demon demon 1704 2月 17 14:44 client.key
-rw-rw-r-- 1 demon demon 948 2月 17 14:44 client.req
-rw-rw-r-- 1 demon demon 1103 2月 17 14:44 client.crt
-rw-rw-r-- 1 demon demon 2807 2月 17 14:44 client.pem
➜ ssl-certs git:(main) ✗
How to check if port is in use on Linux or Unix
sudo lsof -i -P -n | grep LISTEN
sudo netstat -tulpn | grep LISTEN
sudo ss -tulpn | grep LISTEN
sudo lsof -i:22 ## see a specific port such as 22 ##
sudo nmap -sTU -O IP-address-Here
混沌工程
花了两天时间才把这个 istio 重试功能在自己机器上验证通过,必须要记录一下。
笔者按照网络课程或相关书籍配置如下内容:
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: student
name: student
spec:
replicas: 1
selector:
matchLabels:
app: student
template:
metadata:
labels:
app: student
spec:
containers:
- image: 192.168.10.127:5000/new-energy/student:0.3
name: student
ports:
- containerPort: 8080
resources: {}
---
apiVersion: v1
kind: Service
metadata:
labels:
app: student
name: student
spec:
ports:
- port: 8080
name: http
protocol: TCP
targetPort: 8080
selector:
app: student
type: ClusterIP
---
#apiVersion: networking.istio.io/v1alpha3
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: student-route
spec:
hosts:
- student
http:
- route:
- destination:
host: student
retries:
attempts: 3
perTryTimeout: 1s
进入该 student 服务的 student 容器内进行服务调用(注意不是进入 istio-proxy 容器):
### /istio/timeout 接口会延迟 5s 返回
# kubectl -n istio-dev exec -it student-545cff6886-4t955 -c student -- sh
# curl -i -w "@curl-format.txt" http://student:8080/istio/timeout
HTTP/1.1 504 Gateway Timeout
content-length: 24
content-type: text/plain
date: Sun, 12 Feb 2023 15:23:16 GMT
server: envoy upstream request timeout
------------------------------------
time_total: 1.008266s
#
无论怎么调整参数,api 都没有进行重试调用,原因就在于默认的 retryOn 字段不会包含 504 超时错误,通过 istioctl pc route xxx-pod.xxx-namespace -o yaml --name xxx-port 命令可以查看路由:
- name: "8080"
validateClusters: false
virtualHosts:
- domains:
- '*'
includeRequestAttemptCount: true
name: allow_any
routes:
- match:
prefix: /
name: allow_any
route:
cluster: PassthroughCluster
maxGrpcTimeout: 0s
timeout: 0s
- domains:
- student.istio-dev.svc.cluster.local
- student.istio-dev.svc.cluster.local:8080
- student
- student:8080
- student.istio-dev.svc
- student.istio-dev.svc:8080
- student.istio-dev
- student.istio-dev:8080
- 10.96.185.164
- 10.96.185.164:8080
includeRequestAttemptCount: true
name: student.istio-dev.svc.cluster.local:8080
routes:
- decorator:
operation: student.istio-dev.svc.cluster.local:8080/*
match:
prefix: /
metadata:
filterMetadata:
istio:
config: /apis/networking.istio.io/v1alpha3/namespaces/istio-dev/virtual-service/student-route
route:
cluster: outbound|8080||student.istio-dev.svc.cluster.local
maxGrpcTimeout: 0s
retryPolicy:
hostSelectionRetryMaxAttempts: "5"
numRetries: 3
perTryTimeout: 1s
retriableStatusCodes:
- 503
retryHostPredicate:
- name: envoy.retry_host_predicates.previous_hosts
typedConfig:
'@type': type.googleapis.com/envoy.extensions.retry.host.previous_hosts.v3.PreviousHostsPredicate
retryOn: connect-failure,refused-stream,unavailable,cancelled,retriable-status-codes
timeout: 0s
可以看到,默认的 retryOn 值为:connect-failure,refused-stream,unavailable,cancelled,retriable-status-codes 。正是因为条件不匹配,代理在 1s 超时后就直接返回了,不会进行重试。
笔者将 retryOn 的值调整为 5xx 或 gateway-error 就可以了,关于这些错误码可以参阅官网。
附环境信息:
1)Kubernetes version:
➜ ch19 git:(main) ✗ kubectl version --short
Client Version: v1.25.3
Kustomize Version: v4.5.7
Server Version: v1.25.3
➜ ch19 git:(main) ✗
2)Istio version:
➜ ch19 git:(main) ✗ istioctl version
client version: 1.15.5
control plane version: 1.15.5
data plane version: 1.15.5 (3 proxies)
➜ ch19 git:(main) ✗
下载速度太慢,那就开启多线程同时干,推荐 axel 这个工具,以下是同时开启 4 个线程进行下载。
李白追寻旧世界,杜甫开拓新世界,一个开创复古之路的顶峰,一个是开启新时代的大师。
1、永远不要等一个东西降价或是足够便宜才去买。而是你需要的时候就应该买,买回来好好用,产生应有的价值。
2、购物时,同样的商品,不要花太多时间去比价。记住:价格永远是波动的,你不可能总买到作为「最便宜」的东西。这就好比你不可能买到最便宜的股票,然后又在最高点卖出。
3、有更高的意愿为知识而付费,而不是看不起所谓的知识付费。
4、住的地方要离工作的地方近一点。节省通勤时间,更重要的是节省精力。
5、即使在没钱的情况下,也愿意花钱买时间。你的钱是你赚到的某种社会信用,而你的时间是不可再生资源。
6、我如果经济不宽裕不意味着我做出不妥当的事情就有理(比如用盗版软件),也不要总觉得自己被歧视。
7、面子并不值钱。不要动不动就觉得伤自尊了。不要让面子问题成为自己的负资产。
8、无论现在怎么匮乏,但还是应该有一个可以长期坚持做的事情,就像储蓄一样,直到某一天,你可以打开那个「存钱罐」并且可以提取那份价值。比如说学习写作,英语,或是长期锻炼。
9、……
摘录自「小众消息」《说说我自己的「穷人心理」和「穷人生活方式」》
利用 curl 命令的 -w, --write-out <format> 选项,可以打印很多信息,比如处理的时长等,以下是具体用法:
# cat curl-format.txt
\n------------------------------------\n
time_namelookup: %{time_namelookup}s\n
time_connect: %{time_connect}s\n
time_appconnect: %{time_appconnect}s\n
time_pretransfer: %{time_pretransfer}s\n
time_redirect: %{time_redirect}s\n
time_starttransfer: %{time_starttransfer}s\n
----------\n
time_total: %{time_total}s\n
#
# curl -w "@curl-format.txt" -i http://ngx-istio:8080/
HTTP/1.1 200 OK
server: envoy
...
...
------------------------------------
time_namelookup: 0.001505s
time_connect: 0.001578s
time_appconnect: 0.000000s
time_pretransfer: 0.001603s
time_redirect: 0.000000s
time_starttransfer: 5.006996s
----------
time_total: 5.007136s
#
更多用法,可以通过 man curl 进一步了解。
这同样适用于日常写作。
Who am I ?
Where did I come from ?
Where do I go to find out ?