作为SaaS 服务,每个用户在上面都有一些业务配置。如用户的证书配置、用户服务器的流控配置等,这些业务配置相对运维配置来说更加复杂,且可能会有唯一性限制,如按用户 id 唯一。这部分配置数据一般由用户操作触发,代码动态写入,并且通知到各个微服务实例。通常,我们希望这些配置能在界面展示,且支持人为修改。上述逻辑如果由各微服务自己实现,会存在大量重复代码,并且质量无法保证。我们希望由一个公共组件来统一实现这个能力。开源或体量较小的项目就不会选择依赖一个配置中心,而是直接通过连接数据库或etcd来解决问题
每当有新的操作发生的时候,Raft的日志就会增长,然而在实际的系统中,日志并不能无边界地增长。 快照是最简单的压缩日志的方式。在快照中,整个系统的状态写入到持久化存储的快照中,然后在这之前的日志都可以丢弃。 todo 补图 其他方式,像日志清理或lsm树。在数据的一部分子集上面执行,它们均摊了压缩日志的消耗。
Leader创建snapshot,再分发给follower。有如下两个缺点 第一,Server必须选择何时进行快照,如果服务器快照进行地太频繁,将会浪费磁盘带宽和磁盘energy。如果快照太不频繁,会浪费磁盘的存储空间,然后增加了重放日志所需的时间。如果阈值设置地大,时间周期长的话,磁盘开销小。 第二,写快照会消耗较大的时间,我们不希望这个操作延迟了正常的操作。方案是使用Copy on write技术,这样子在不影响snapshot写入的情况下,集群可以接受新的更新。
// // Created by 张俭 on 2021/4/26. // #include<stdio.h> #include<unistd.h> #include<string.h>
intmain(int argc, char *argv[]) { int i = 0; pid_t mypid = getpid(); if (argc == 1) return1; printf("argc = %d and arguments are:\n", argc); for (i; i < argc; i++) { printf("%d = %s\n", i, argv[i]); } fflush(stdout); sleep(30); printf("Replacing first argument with x:es... Now open another terminal and run: ps p %d\n", (int)mypid); memset(argv[1], 'x', strlen(argv[1])); getc(stdin); return0; }
编译并运行
1 2 3 4 5 6 7
gcc password_hide.c [root@c77dc365cd1a sh]# ./a.out abcd argc = 2 and arguments are: 0 = ./a.out 1 = abcd Replacing first argument with x:es... Now open another terminal and run: ps p 55
# Point to the internal API server hostname APISERVER=https://kubernetes.default.svc # Path to ServiceAccount token SERVICEACCOUNT=/var/run/secrets/kubernetes.io/serviceaccount # Read this Pod's namespace NAMESPACE=$(cat${SERVICEACCOUNT}/namespace) # Read the ServiceAccount bearer token TOKEN=$(cat${SERVICEACCOUNT}/token) # Reference the internal certificate authority (CA) CACERT=${SERVICEACCOUNT}/ca.crt # Explore the API with TOKEN curl --cacert ${CACERT} --header "Authorization: Bearer ${TOKEN}" -X GET ${APISERVER}/api curl --cacert ${CACERT} --header "Authorization: Bearer ${TOKEN}" -X GET ${APISERVER}/api/v1/namespaces/default/pods
Alternatively, if you are the root user, you can run:
export KUBECONFIG=/etc/kubernetes/admin.conf
You should now deploy a pod network to the cluster. Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at: https://kubernetes.io/docs/concepts/cluster-administration/addons/
You can now join any number of the control-plane node running the following command on each as root:
Please note that the certificate-key gives access to cluster sensitive data, keep it secret! As a safeguard, uploaded-certs will be deleted in two hours; If necessary, you can use "kubeadm init phase upload-certs --upload-certs" to reload certs afterward.
Then you can join any number of worker nodes by running the following on each as root:
privatestatic String conv2Str(int value, int length) { if (length > 5) { thrownewIllegalArgumentException("length should be less than 5"); } Stringstr= String.valueOf(value); return AUX_ARRAY[length - str.length()] + str; }