关于证书
关于cfssl工具:
cfssl :证书签发的主要工具
cfssl-json :将cfssl生成的证书( json格式)变为文件承载式证书
cfssl-certinfo :验证证书的信息
cfssl-certinfo -cert 证书名称
可以查看证书的信息
CN: Common Name ,浏览器使用该字段验证网站是否合法, 一般写的是域名。非常重要。浏览器使用该字段验证网站是否合法 C: Country,国家ST:State,州,省L: Locality ,地区,城市O: Organization Name ,组织名称,公司名称OU: Organization Unit Name ,组织单位名称,公司部门
查看域名证书
[root@alice001 ~]# cfssl-certinfo -domain www.dkaiyun.com
{
"subject": {
"common_name": "www.dkaiyun.com",
"names": [
"www.dkaiyun.com"
]
},
"issuer": {
"common_name": "Encryption Everywhere DV TLS CA - G1",
"country": "US",
"organization": "DigiCert Inc",
"organizational_unit": "www.digicert.com",
"names": [
"US",
"DigiCert Inc",
"www.digicert.com",
"Encryption Everywhere DV TLS CA - G1"
]
},
"serial_number": "7884455399703283302427254215251353882",
"sans": [
"www.dkaiyun.com",
"dkaiyun.com"
],
"not_before": "2020-05-15T00:00:00Z",
"not_after": "2021-05-15T12:00:00Z",
"sigalg": "SHA256WithRSA",
"authority_key_id": "55:74:4F:B2:72:4F:F5:60:BA:50:D1:D7:E6:51:5C:9A:1:87:1A:D7",
"subject_key_id": "1B:1:E3:17:14:7:2C:35:47:F3:20:B:AA:1C:45:CE:1B:71:4D:4A",
"pem": "-----BEGIN CERTIFICATE-----\nMIIFlTCCBH2gAwIBAgIQBe59qfsFlqpqZ73o+rBhGjANBgkqhkiG9w0BAQsFADBu\nMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3\nd3cuZGlnaWNlcnQuY29tMS0wKwYDVQQDEyRFbmNyeXB0aW9uIEV2ZXJ5d2hlcmUg\nRFYgVExTIENBIC0gRzEwHhcNMjAwNTE1MDAwMDAwWhcNMjEwNTE1MTIwMDAwWjAa\nMRgwFgYDVQQDEw93d3cuZGthaXl1bi5jb20wggEiMA0GCSqGSIb3D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AiB9yPeR\nDJsDMzfo8kFGrqCTtwslqNf17ZAASQLSVAc0CAB3AFzcQ5L+5qtFRLFemtRW5hA3\n+9X6R9yhc5SyXub2xw7KAAABchbQEnMAAAQDAEgwRgIhAKZHTFNCgTAPlEY4uBMt\nYIc8Z/fvAYZ+VG3AeoY7zklSAiEA9BCOW7Vxjhi1lY4gMpCm1rKw5Gt9vsgcXfiP\nhbU2hlwwDQYJKoZIhvcNAQELBQADggEBAK7mdNnCPEoXtftZQbRvXL4HzmcnS2Fa\nGWiEvudYNIAc5+iS50a2pGLaoumptikzNYHcUMIrHUelZCX5bNW+07fCF5S6gWKC\n9NvbdQujz92BM9z2cmm8aeHHr4cCF0HRe8RsPJ09jZg71FH+NZZICg9LROdJyrak\nwWm27TBpJiKxo/VfNck9WUfKmPFhhsByCsdNfYc/SXhktvIE4DqCtV+og/c9V7c0\npsUQZGgWE/eKE+E88IAQLO8egWz6nM/n5C0MHj+kdqh+n7ukN8G/wJddEbPv7ffY\nposLY2D8vbP8s2/GPzLhsu4b47NfvxDa9lTXoMnJGzbHCeTQ+MwhRNM=\n-----END CERTIFICATE-----\n"
}
关于kubeconfig文件: .
这是一个K8S用户的配置文件
它里面含有证书信息
证书过期或更换,需要同步替换该文件
kubelet.kubeconfig 可以反解出ca.pem 详细操作如下
[root@alice002 conf]# cat kubelet.kubeconfig
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: LS0tLS1CRUdJTiBRUdJTiBDRQ0FURRUdJTiBDRR0RENDQXB5Z0F3SUJBZ0lVT2F6RW9lQ1FFTnQxaGpIdmRTekRNaDFSL0Zzd0RRWUpLb1pJaHZjTkFRRUwKQlFBd1lERUxNQWtHQTFVRUJoTUNRMDR4RURBT0JnTlZCQWdUQjJKbGFXcHBibWN4RURBT0JnTlZCQWNUQjJKbAphV3BwYm1jeEN6QUpCZ05WQkFvVEFtOWtNUXd3Q2dZRFZRUUxFd052Y0hNeEVqQVFCZ05WQkFNVENVOXNaR0p2CmVVVmtkVE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OHlHb3JHdXVWbFoxYXZwYzFYSmhsQVBsMnZsQXBiNi9lcXUza2xtMC9LL0gvcGVYZDJkak8KVFNVdGZmb2RqbnlEZHJTV2NKS3JRaTViWjZacmVxbTAxUzRCRXVGRE4xTk9vR1E0SWQ1Mk10bWRmOG53eWIxcgpIOWh6MDlFNVlsU0JRWk8zVXI0OEtRcHlHa1VVbWR3eTBxSzRIMEdaVjZhcE9jang3SHdSY3NkdWNvYXZGWmk2Cm9XT2hGeFRZSGhvdE5nc3EwWTRuQjhjbkJIZmhFc0xjUDRqMHkxdkpKS2FLaVNSQ0lVbnBpZnNIcFdnWEhHblEKa21PZm9PRmRlZXhOME1OU3A3WVdRUmhjR09UVU83aWhrNDFwRUkwQmNUZXJzSW1Hak9QK0h3PT0KLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo=
server: https://172.23.187.175:7443
name: myk8s
contexts:
- context:
cluster: myk8s
user: k8s-node
name: myk8s-context
current-context: myk8s-context
kind: Config
preferences: {}
users:
- name: k8s-node
user:
client-certificate-data: LS0tLS1CRUdJTiBDRRUdJTiBDRFURS0tLS0tCk1JSUR3akNDQXFxZ0F3SUJBZ0lVUHAxc0JSb3JkUklKZXlnR0c4aExHTlZEZXY4d0RRWUpLb1pJaHZjTkFRRUwKQlFBd1lERUxNQWtHQTFVRUJoTUNRMDR4RURBT0JnTlZCQWdUQjJKbGFXcHBibWN4RURBT0JnTlZCQWNUQjJKbAphV3BwYm1jeEN6QUpCZ05WQkFvVEFtOWtNUXd3Q2dZRFZRUUxFd052Y0hNeEVqQVFCZ05WQkFNVENVOXNaR0p2CmVVVmtkVEFlRncweU1UQXhNekF3T0RRNU1EQmFGdzAwTVRBeE1qVXdPRFE1TURCYU1GOHhDekFKQmdOVkJBWVQKQWtOT01SQXdEZ1lEVlFRSUV3ZGlaV2xxYVc1bk1SQXdEZ1lEVlFRSEV3ZGlaV2xxYVc1bk1Rc3dDUVlEVlFRSwpFd0p2WkRFTU1Bb0dBMVVF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Q0lVbnBpZnNIcFdnWEhHblEKa21PZm9PRmRlZXhOME1OU3A3WVdRUmhjR09UVU83aWhrNDFwRUkwQmNUZXJzSW1Hak9QK0h3PT0KLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo=" |base64 -d >123.pem
[root@alice002 conf]#
[root@alice002 conf]# ll
total 28
-rw-r--r-- 1 root root 1346 Feb 7 11:02 123.pem
-rw-r--r-- 1 root root 2223 Jan 30 17:42 audit.yaml
-rw-r--r-- 1 root root 258 Jan 30 20:20 k8s-node.yaml
-rw------- 1 root root 6204 Jan 30 20:18 kubelet.kubeconfig
-rw------- 1 root root 6220 Jan 31 09:26 kube-proxy.kubeconfig
[root@alice002 conf]# md5sum 123.pem
7e349d25185bc1d1ec836e00b6a31b48 123.pem
[root@alice002 conf]# ll /opt/kubernetes/server/bin/c
certs/ cloud-controller-manager cloud-controller-manager.docker_tag
[root@alice002 conf]# ll /opt/kubernetes/server/bin/certs/ca.pem
-rw-r--r-- 1 root root 1346 Jan 30 17:40 /opt/kubernetes/server/bin/certs/ca.pem
[root@alice002 conf]# md5sum /opt/kubernetes/server/bin/certs/ca.pem
7e349d25185bc1d1ec836e00b6a31b48 /opt/kubernetes/server/bin/certs/ca.pem
[root@alice002 conf]#
资源
Pod
为什么pod必须是原子调度单位
- 进程组概念 Pod = “进程组”
- 有些容器需要紧密合作 需要在同一个宿主机上 (业务容器 日志转发容器) 亲密关系-调度解决
Pod 里面的容器是“超亲密关系”
超亲密关系-pod解决
- 比如说两个进程之间会发生文件交换,一个写日志,一个读日志;
- 两个进程之间需要通过 localhost 或者说是本地的 Socket 去进行通信,这种本地通信也是超亲密关系;
- 这两个容器或者是微服务之间,需要发生非常频繁的 RPC 调用,出于性能的考虑,也希望它们是超亲密关系;
两个容器或者是应用,它们需要共享某些 Linux Namespace。最简单常见的一个例子,就是我有一个容器需要加入另一个容器的 Network Namespace。这样我就能看到另一个容器的网络设备,和它的网络信息。
Pod要解决的问题 共享网络和存储。
共享网络
启动一个infra container 共享Network Namespace其他容器加入到 Infra container 的 Network Namespace 中。
整个 Pod 里面,必然是 Infra container 第一个启动。并且整个 Pod 的生命周期是等同于 Infra container 的生命周期的,与容器A 和 B 是无关的。共享存储
容器设计模式
InitContainer
首先启动 退出后 启动别的容器 tomcat+war包 (war包cp到emptydir第二个容器挂emptydir)
Sidecar
sidecar 通过在Pod里定义专门容器,来执行主业务容器需要的辅助工作
原本需要在容器里面执行 SSH 需要干的一些事情,可以写脚本、一些前置的条件,其实都可以通过像 Init Container 或者另外像 Sidecar 的方式去解决;
- 当然还有一个典型例子就是我的日志收集,日志收集本身是一个进程,是一个小容器,那么就可以把它打包进 Pod 里面去做这个收集工作;
- 还有一个非常重要的东西就是 Debug 应用,实际上现在 Debug 整个应用都可以在应用 Pod 里面再次定义一个额外的小的 Container,它可以去 exec 应用 pod 的 namespace;
- 查看其他容器的工作状态,这也是它可以做的事情。不再需要去 SSH 登陆到容器里去看,只要把监控组件装到额外的小容器里面就可以了,然后把它作为一个 Sidecar 启动起来,跟主业务容器进行协作,所以同样业务监控也都可以通过 Sidecar 方式来去做。
优势:
辅助功能从业务容器解耦,所以我就能够独立发布 Sidecar 容器,
更重要的是这个能力是可以重用的,即同样的一个监控 Sidecar 或者日志 Sidecar,可以被全公司的人共用
Deployment
示例yaml
Pod 的 ownerReferences 即 Pod 所属的 controller 资源,并不是 Deployment,而是一个 ReplicaSet。
这个 ReplicaSet 的 name,其实是 nginx-deployment 加上 pod.template-hash
所有的 Pod 都是 ReplicaSet 创建出来的,而 ReplicaSet 它对应的某一个具体的 Deployment.template 版本。
[root@alice002 ~]# kubectl get replicasets
NAME DESIRED CURRENT READY AGE
resume-7d7567dcd5 3 3 3 4d12h
DESIRED:期望的 Pod 数量是 3 个; CURRENT:当前实际 Pod 数量是 3 个; UP-TO-DATE:其实是到达最新的期望版本的 Pod 数量 AVAILABLE:这个其实是运行过程中可用的 Pod 数量。这里 AVAILABLE 并不简单是可用的,也就是 Ready 状态的,它其实包含了一些可用超过一定时间长度的 Pod; AGE:deployment 创建的时长,如上图 Deployment 就是已经创建了 80 分钟。
常用命令
修改镜像
kubectl set image deployment.v1.apps/resume nginx=nginx:1.9.1
kubectl set image 资源名.资源版本.资源组/deployment名 container名=镜像名
快速回滚到上一个版本
kubectl rollout undo deployment.v1.apps/nginx-deployment
Deployment 中的字段解析
spec 字段:
MinReadySeconds:30 Pod ready 超过 30 秒之后才认为 Pod 是 available 的 revisionHistoryLimit: 保留历史 revision,即保留历史 ReplicaSet 的数量,默认值为 10 个paused:paused 是标识,Deployment 只做数量维持,不做新的发布,这里在 Debug 场景可能会用到;progressDeadlineSeconds:当 Deployment 处于扩容或者发布状态时,它会处于一个 processing 的状态,processing 可以设置一个超时时间。如果超过超时时间还处于 processing,那么 controller 将认为这个 Pod 会进入 failed 的状态。
升级策略字段
MaxUnavailable:滚动过程中最多有多少个 Pod 不可用;默认25% MaxSurge:滚动过程中最多存在多少个 Pod 超过预期 replicas 数量 默认25%
要注意的是 MaxSurge 和 MaxUnavailable 不能同时为 0
管理模式
- Deployment只负责管理不同版本的ReplicaSet, 由ReplicaSet管理Pod副本数 每个ReplicaSet对应了Deployment template的一个版本 一个ReplicaSet下的Pod都是相同的版本
- Deployment 管理多版本的方式,是针对每个版本的 template 创建一个 ReplicaSet,由 ReplicaSet 维护一定数量的 Pod 副本,而 Deployment 只需要关心不同版本的 ReplicaSet 里要指定多少数量的 Pod;
- 因此,Deployment 发布部署的根本原理,就是 Deployment 调整不同版本 ReplicaSet 里的终态副本数,以此来达到多版本 Pod 的升级和回滚。
job
[root@alice002 ~]# kubectl get job
NAME COMPLETIONS DURATION AGE
pi 10/10 88s 20h
DURATION Job 里面的实际业务到底运行了多长时间,当我们的性能调优的时候,这个参数会非常的有用。 COMPLETIONS 主要来看我们任务里面这个 Pod 一共有几个,然后它其中完成了多少个状态
字段
completions 这个 Job 指定的可以运行的总次数。比如这里设置成 8,即这个任务一共会被执行 8 次;
parallelism 并行执行的个数 把它设置成 2,也就是说这个 Job 一定要执行 8 次,每次并行 2 个 Pod,这样的话,一共会执行 4 个批次
Cronjob
schedule:设置时间格式,它的时间格式和 Linux 的 crontime 是一样的 startingDeadlineSeconds:即:每次运行 Job 的时候,它最长可以等多长时间,有时这个 Job 可能运行很长时间也不会启动。所以这时,如果超过较长时间的话,CronJob 就会停止这个 Job; concurrencyPolicy:就是说是否允许并行运行。第二个 Job 要到时间需要去运行的时候,上一个 Job 还没完成。如果这个 policy 设置为 true 的话,那么不管你前面的 Job 是否运行完成,每分钟都会去执行;如果是 false,它就会等上一个 Job 运行完成之后才会运行下一个; JobsHistoryLimit:指定任务历史存留数
管理模式
- Job Controller负责根据配置创建Pod
- Job Controller跟踪Job状态,根据配置及时重试Pod或者继续创建
- Job Controller会自动添加label来跟踪对应的pod,并根据配置并行或者串行创建Pod
DaemonSet
更新策略
RollingUpdate 其实比较好理解,就是会一个一个的更新。先更新第一个 pod,然后老的 pod 被移除,通过健康检查之后再去见第二个 pod,这样对于业务上来说会比较平滑地升级,不会中断;
OnDelete 模板更新之后,pod 不会有任何变化,需要我们手动控制。删除某一个节点对应的 pod,它就会重建,不删除的话它就不会重建