接上一篇博客,Configmap语法规则和用法与secret是一样的。只不过secret是加密的,configmap是明文的,明文的就不适合密码的传递,不安全,但是你说非要这么用能不能行,当然可以,但是不建议。configmap是明文的就更适合参数文件和配置文件的传递。
后面就是探针的一些知识了。
探针
通过deployment创建pod,非常方便。也有了高可用。思考一个问题:pod状态一直是running,但是里面的文件丢失了怎么办?deploy是管不了的。
需要有另外一种探测方式,叫探针,就是探察探测这个pod是否是正常工作的。
它会根据发现的问题,处理的方式也会不同,有两种探测方式:liveness probe 存活探针/readiness probe 就绪探针 1.16版本新增startup probe 启动探针
那如何知道是否是好的呢?3种方式:command/httpget/tcp
存活探针,就绪探针,启动探针里面都支持command/httpget/tcp3种方式,我们只会把存活探针的3种方式讲清楚,其他两种探针里面的这三种方式里面的语法和存活探针是一样的
command适用的场景是执行Linux命令的场景去探测,那如果你是一个网站呢,是一个网站服务呢,他就适合于用http去探测,如果你是针对于端口,查看某一个端口有没有去放行,那么就适合用tcp去探测
存活探针liveness probe
一旦发现问题,它会重启容器
所谓的存活探针,就是pod的状态是running的状态下,根据探针去探测应用程序是否存活,探测应用程序所对应的配置文件,参数文件是否存在,这个叫存活探针
重启大法,或者重装(这里重启表示的是重建,是在原pod基础上重建文件,不是删除原pod再创建新的pod)。
[root@master ~]# cat pod11.yaml
apiVersion: v1
kind: Pod
metadata:
labels:
test: liveness
name: liveness-exec
spec:
containers:
- name: liveness
image: registry.cn-hangzhou.aliyuncs.com/tianhairui/busybox:666
imagePullPolicy: IfNotPresent
args:
- /bin/sh
- -c
- touch /tmp/healthy; sleep 30; rm -f /tmp/healthy; sleep 600
livenessProbe:
exec:
command:
- cat
- /tmp/healthy
initialDelaySeconds: 5
periodSeconds: 5
[root@master ~]# kubectl apply -f pod11.yaml
[root@master ~]# kubectl get pod liveness-exec -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
liveness-exec 1/1 Running 3 (14s ago) 4m 10.244.166.149 node1 <none> <none>
就绪探针readiness probe
liveness probe 存活探针通过重启来解决问题
readiness probe 检测到问题并不重启,只是svc接受的请求不再转发给此pod
我们用就绪探针来探测pod里面的文件还在不在,文件在pod就是就绪状态的,文件不在pod就是非就绪状态,非就绪状态的pod,被svc识别到之后就不会把前端的流量发送到这个pod上了,只会负载均衡的发送到就绪的pod上,而且非就绪状态的pod,也不会被重建
[root@master ~]# cat web.yaml
假如没有这个就绪探针,我们随机删除一个pod里面的配置文件
[root@master ~]# kubectl create deployment web2 --image swr.cn-north-4.myhuaweicloud.com/tianmeili/nginx:1.0 --dry-run=client -o yaml > web2.yaml
[root@master ~]# vim web2.yaml
[root@master ~]# cat web2.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: web2
name: web2
spec:
replicas: 3
selector:
matchLabels:
app: web2
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: web2
spec:
containers:
- image: swr.cn-north-4.myhuaweicloud.com/tianmeili/nginx:1.0
imagePullPolicy: IfNotPresent
name: nginx
resources: {}
status: {}
[root@master ~]# kubectl apply -f web2.yaml
[root@master ~]# kubectl get po
web2-d7867d984-bjb59 1/1 Running 0 6s
web2-d7867d984-dxmc2 1/1 Running 0 6s
web2-d7867d984-lk29l 1/1 Running 0 6s
创建SVC
[root@master ~]# kubectl expose deployment web2 --name web2svc --port 80 --target-port 80 --type NodePort
service/web2svc exposed
[root@master ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
web2svc NodePort 10.102.239.42 <none> 80:30549/TCP 2s
修改内容
[root@master ~]# kubectl exec -ti web2-d7867d984-bjb59 -- sh -c 'echo 111 > /usr/share/nginx/html/index.html'
[root@master ~]# kubectl exec -ti web2-d7867d984-dxmc2 -- sh -c 'echo 222 > /usr/share/nginx/html/index.html'
[root@master ~]# kubectl exec -ti web2-d7867d984-lk29l -- sh -c 'echo 333 > /usr/share/nginx/html/index.html'
[root@master ~]# kubectl describe svc web2svc
Name: web2svc
Namespace: abc
Labels: app=web2
Annotations: <none>
Selector: app=web2
Type: NodePort
IP Family Policy: SingleStack
IP Families: IPv4
IP: 10.102.239.42
IPs: 10.102.239.42
Port: <unset> 80/TCP
TargetPort: 80/TCP
NodePort: <unset> 30549/TCP
Endpoints: 10.244.104.26:80,10.244.166.143:80,10.244.166.165:80
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
[root@master ~]# curl 10.102.239.42
观察效果
之后,故意删除某个pod的文件
[root@master ~]# kubectl exec -ti web2-d7867d984-lk29l -- sh -c 'rm -rf /usr/share/nginx/html/index.html'
[root@master ~]# curl 10.102.239.42
111
[root@master ~]# curl 10.102.239.42
222
[root@master ~]# curl 10.102.239.42
<html>
<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx/1.19.6</center>
</body>
</html>
这时候访问的时候,有概率就会出错,非常不友好。通过就绪探针即可解决。
[root@master ~]# vim web2.yaml
[root@master ~]# cat web2.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: web2
name: web2
spec:
replicas: 3
selector:
matchLabels:
app: web2
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: web2
spec:
containers:
- image: swr.cn-north-4.myhuaweicloud.com/tianmeili/nginx:1.0
imagePullPolicy: IfNotPresent
name: nginx
resources: {}
readinessProbe:
httpGet:
path: /index.html
port: 80
initialDelaySeconds: 3
periodSeconds: 3
status: {}
[root@master ~]# kubectl apply -f web2.yaml
[root@master ~]# kubectl describe svc web2svc
Name: web2svc
Namespace: abc
Labels: app=web2
Annotations: <none>
Selector: app=web2
Type: NodePort
IP Family Policy: SingleStack
IP Families: IPv4
IP: 10.102.239.42
IPs: 10.102.239.42
Port: <unset> 80/TCP
TargetPort: 80/TCP
NodePort: <unset> 30549/TCP
Endpoints: 10.244.104.27:80,10.244.166.156:80,10.244.166.162:80
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
[root@master ~]# kubectl exec -ti web2-5d68fbb64-765pl -- sh -c 'echo 111 > /usr/share/nginx/html/index.html'
[root@master ~]# kubectl exec -ti web2-5d68fbb64-7bvsw -- sh -c 'echo 222 > /usr/share/nginx/html/index.html'
[root@master ~]# kubectl exec -ti web2-5d68fbb64-pjnlk -- sh -c 'echo 333 > /usr/share/nginx/html/index.html'
[root@master ~]# curl 10.102.239.42
222
这时候故意删除某个index.html
[root@master ~]# kubectl exec -ti web2-5d68fbb64-7bvsw -- sh -c 'rm -rf /usr/share/nginx/html/index.html'
[root@master ~]# kubectl get pod
NAME READY STATUS RESTARTS AGE
web2-5d68fbb64-765pl 1/1 Running 0 2m50s
web2-5d68fbb64-7bvsw 0/1 Running 0 2m46s
web2-5d68fbb64-pjnlk 1/1 Running 0 2m56s
[root@master ~]# kubectl describe svc web2svc
Name: web2svc
Namespace: abc
Labels: app=web2
Annotations: <none>
Selector: app=web2
Type: NodePort
IP Family Policy: SingleStack
IP Families: IPv4
IP: 10.102.239.42
IPs: 10.102.239.42
Port: <unset> 80/TCP
TargetPort: 80/TCP
NodePort: <unset> 30549/TCP
Endpoints: 10.244.104.27:80,10.244.166.156:80
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
尝试访问,就不会把流量转发到后端有问题的pod上了。
能否配置刚才将的存活探针一起使用呢?可以
存活探针一旦探测到有问题,就会重启;
就绪探针一旦探测到有问题,会把endpoint地址从svc删除。
例如:
[root@master ~]# vim web2.yaml
[root@master ~]# cat web2.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: web2
name: web2
spec:
replicas: 3
selector:
matchLabels:
app: web2
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: web2
spec:
containers:
- image: swr.cn-north-4.myhuaweicloud.com/tianmeili/nginx:1.0
imagePullPolicy: IfNotPresent
name: nginx
resources: {}
readinessProbe:
httpGet:
path: /index.html
port: 80
initialDelaySeconds: 3
periodSeconds: 3
livenessProbe:
httpGet:
path: /index.html
port: 80
initialDelaySeconds: 3
periodSeconds: 3
status: {}
[root@master ~]# kubectl apply -f web2.yaml
通过命令只返回状态码 200的就是正常的
[root@master ~]# echo $(curl -sIL -w "%{http_code}" -o /dev/null 10.102.239.42)
200
删除某个pod的index,观察svc的endpoint
[root@master ~]# kubectl exec -ti web2-5d7bccfd7b-h82nt -- sh -c 'rm -rf /usr/share/nginx/html/index.html'
[root@master ~]# kubectl describe svc web2svc
Name: web2svc
Namespace: abc
Labels: app=web2
Annotations: <none>
Selector: app=web2
Type: NodePort
IP Family Policy: SingleStack
IP Families: IPv4
IP: 10.102.239.42
IPs: 10.102.239.42
Port: <unset> 80/TCP
TargetPort: 80/TCP
NodePort: <unset> 30549/TCP
Endpoints: 10.244.104.41:80,10.244.166.159:80,10.244.166.163:80
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
[root@master ~]# kubectl describe svc web2svc
Name: web2svc
Namespace: abc
Labels: app=web2
Annotations: <none>
Selector: app=web2
Type: NodePort
IP Family Policy: SingleStack
IP Families: IPv4
IP: 10.102.239.42
IPs: 10.102.239.42
Port: <unset> 80/TCP
TargetPort: 80/TCP
NodePort: <unset> 30549/TCP
Endpoints: 10.244.166.159:80,10.244.166.163:80
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
[root@master ~]# kubectl describe svc web2svc
Name: web2svc
Namespace: abc
Labels: app=web2
Annotations: <none>
Selector: app=web2
Type: NodePort
IP Family Policy: SingleStack
IP Families: IPv4
IP: 10.102.239.42
IPs: 10.102.239.42
Port: <unset> 80/TCP
TargetPort: 80/TCP
NodePort: <unset> 30549/TCP
Endpoints: 10.244.104.41:80,10.244.166.159:80,10.244.166.163:80
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
startup启动探针:
apiVersion: v1
kind: Pod
metadata:
labels:
test: liveness
name: pod2
spec:
containers:
- name: pod2
image: nginx
imagePullPolicy: IfNotPresent
livenessProbe:
httpGet:
path: /index.html
port: 80
initialDelaySeconds: 3
periodSeconds: 3
startupProbe:
httpGet:
path: /healthz
port: liveness-port
failureThreshold: 30
periodSeconds: 10
它的优先级是最高的,且只在容器启动过程中(就绪之前)运行一次。
一旦完成任务,就不会周期执行了。
livenessprobe 存活periodSeconds: 3 每隔3秒检测一次,一旦检测不成功,会重启。
假如定义了一个POD,这个pod里面要运行一个应用程序,这个程序有点大,例如程序启动过程需要60秒。
这时候就会进入到无限循环中。
初始化和依赖项准备:有时,容器在启动后可能需要一些额外的时间来完成初始化过程。这可能涉及数据库连接、加载配置文件或进行其他初始化任务。在这种情况下,使用 startupProbe 可以确保容器在完全初始化完成之前不会接收流量。同时,您还可以定义依赖项,如数据库或其他服务是否已准备就绪,使得容器能够正确运行。
避免不必要的重启:在容器启动的早期阶段,应用程序可能尚未完全启动,或者依赖项尚未就绪。如果此时将流量发送到容器,可能会导致应用程序出现故障或功能不完整。通过使用 startupProbe,可以确保在容器完全启动并准备好接收流量之前,不会将流量发送到容器,从而避免了不必要的重启。
自愈能力:在某些情况下,应用程序可能会在启动过程中出现故障。如果没有正确的探测机制,并及时采取适当的恢复措施,应用程序可能会持续失败或导致其他问题。使用 startupProbe 可以帮助 Kubernetes 在启动过程中自动检测并处理出现的问题,并执行相应的重启策略。
startupProbe 的意义在于确保容器在启动过程中顺利完成且准备就绪,以提供稳定的服务并避免不必要的应用程序故障。它是一种有助于提高可靠性和自愈能力的重要机制。
startup 启动探针
startup探针仅在容器启动的时候发生作用,一旦完成(单次),后续就不会再运行了。
startup -- 优先级最高
liveness
readeness
三个探针可以同时存在
在 Kubernetes 中,readinessProbe、livenessProbe 和 startupProbe 是三种不同用途的探针,用于监测容器的健康状态。下面是它们的区别:
readinessProbe(就绪性探针):
作用: 用于确定容器是否已准备好接收网络流量。
触发条件: 当 readinessProbe 返回成功(HTTP 状态码200-399)时,容器被认为已准备好,可以接收流量;否则,它被标记为未准备好,不会接收流量。
使用场景: 在应用程序需要一些启动时间来初始化或在启动后可能出现短暂的不可用状态时使用。
livenessProbe(活跃性探针):
作用: 用于确定容器是否在运行状态。
触发条件: 当 livenessProbe 返回失败(非 HTTP 状态码200-399)时,容器被认为失败,Kubernetes 将尝试重新启动该容器。
使用场景: 在应用程序可能进入死锁或无响应状态时使用,以便及时检测并重新启动容器。
startupProbe(启动性探针):
作用: 用于确定容器是否已完成启动和初始化。
触发条件: startupProbe 在容器启动后的初始一段时间内运行,并在此期间确定容器是否准备好接收流量。与 readinessProbe 不同,startupProbe 只在启动阶段运行一次。
使用场景: 在应用程序启动时可能需要一些时间来初始化或完成一些特定任务时使用。它不会阻止流量,但可以确保应用程序在接收流量之前已经初始化。
job与cronjob
job单次任务
cronjob 循环任务
job/cronjob 任务负载
deployment 无状态工作负载
statefulset 有状态工作负载
[root@master ~]# cat job.yaml
apiVersion: batch/v1
kind: Job
metadata:
name: pi-hehe
spec:
template:
spec:
containers:
- name: pi-hehe
image: registry.cn-hangzhou.aliyuncs.com/cloudcs/perl:5.34.0
imagePullPolicy: IfNotPresent
command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"]
restartPolicy: Never
[root@master ~]# kubectl get pod
NAME READY STATUS RESTARTS AGE
pi-hehe-qs28q 0/1 Completed 0 6m1s
[root@master ~]# kubectl logs pi-hehe-qs28q
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632788659361533818279682303019520353018529689957736225994138912497217752834791315155748572424541506959508295331168617278558890750983817546374649393192550604009277016711390098488240128583616035637076601047101819429555961989467678374494482553797747268471040475346462080466842590694912933136770289891521047521620569660240580381501935112533824300355876402474964732639141992726042699227967823547816360093417216412199245863150302861829745557067498385054945885869269956909272107975093029553211653449872027559602364806654991198818347977535663698074265425278625518184175746728909777727938000816470600161452491921732172147723501414419735685481613611573525521334757418494684385233239073941433345477624168625189835694855620992192221842725502542568876717904946016534668049886272327917860857843838279679766814541009538837863609506800642251252051173929848960841284886269456042419652850222106611863067442786220391949450471237137869609563643719172874677646575739624138908658326459958133904780275901
华为官方的例子如下
[root@master ~]# cat job3.yaml
apiVersion: batch/v1
kind: Job
metadata:
name: piip3
spec:
completions: 10 # 运行的次数,即Job结束需要成功运行的Pod个数
parallelism: 2 # 并行运行Pod的数量,默认为1
backoffLimit: 5 # 表示失败Pod的重试最大次数,超过这个次数不会继续重试。
activeDeadlineSeconds: 600 # 表示Pod超期时间,一旦达到这个时间,Job及其所有的Pod都会停止。
template: # Pod定义
spec:
containers:
- name: piip3
image: registry.cn-hangzhou.aliyuncs.com/cloudcs/perl:5.34.0
command:
- perl
- "-Mbignum=bpi"
- "-wle"
- print bpi(2000)
restartPolicy: Never
[root@master ~]# kubectl apply -f job3.yaml
[root@master ~]# kubectl get pod
NAME READY STATUS RESTARTS AGE
piip3-2bjqn 0/1 Completed 0 52s
piip3-5gplr 0/1 Completed 0 42s
piip3-7wl5k 0/1 Completed 0 73s
piip3-88kqf 0/1 Completed 0 62s
piip3-8n55n 0/1 Completed 0 52s
piip3-bgxd5 0/1 Completed 0 32s
piip3-fgtq2 0/1 Completed 0 42s
piip3-hxgg9 0/1 Completed 0 73s
piip3-mr4z4 0/1 Completed 0 62s
piip3-zm6nv 0/1 Completed 0 32s
如果要完成后,自动清理job,可以带上参数
[root@master ~]# cat job4.yaml
apiVersion: batch/v1
kind: Job
metadata:
name: piip4
spec:
ttlSecondsAfterFinished: 30 # 变为completed 之后,等待多久自动删除
completions: 4 # 运行的次数,即Job结束需要成功运行的Pod个数
parallelism: 1 # 并行运行Pod的数量,默认为1
backoffLimit: 5 # 表示失败Pod的重试最大次数,超过这个次数不会继续重试。
activeDeadlineSeconds: 600 # 表示Pod超期时间,一旦达到这个时间,Job及其所有的Pod都会停止。
template: # Pod定义
spec:
containers:
- name: piip4
image: registry.cn-hangzhou.aliyuncs.com/cloudcs/perl:5.34.0
command:
- perl
- "-Mbignum=bpi"
- "-wle"
- print bpi(2000)
restartPolicy: Never
cronjob周期性任务,每隔1分钟打印当前时间
[root@master ~]# kubectl create cronjob my-job --image=registry.cn-hangzhou.aliyuncs.com/tianhairui/busybox:666 --schedule="*/1 * * * *" --dry-run=client -o yaml -- sh -c "echo \$(date \"+%Y-%m-%d %H:%M:%S\")" > myjob3.yaml
[root@master ~]# vim myjob3.yaml
[root@master ~]# cat myjob3.yaml
apiVersion: batch/v1
kind: CronJob
metadata:
creationTimestamp: null
name: my-job
spec:
jobTemplate:
metadata:
creationTimestamp: null
name: my-job
spec:
template:
metadata:
creationTimestamp: null
spec:
containers:
- command:
- sh
- -c
- echo $(date "+%Y-%m-%d %H:%M:%S")
image: registry.cn-hangzhou.aliyuncs.com/tianhairui/busybox:666
name: my-job
resources: {}
restartPolicy: OnFailure
schedule: '*/1 * * * *'
status: {}
[root@master ~]# kubectl apply -f myjob3.yaml
[root@master ~]# kubectl get pod
NAME READY STATUS RESTARTS AGE
my-job-28739759-wb979 0/1 Completed 0 22s
[root@master ~]# kubectl logs my-job-28739759-wb979
2024-08-23 03:59:01
[root@master ~]# kubectl logs my-job-28739761-dj27v
2024-08-23 04:01:01
helm
看代码笔记
[root@master ~]# tar -zxvf helm-v3.15.4-linux-amd64.tar.gz
[root@master ~]# cd linux-amd64/
[root@master linux-amd64]#
[root@master linux-amd64]# pwd
/root/linux-amd64
[root@master linux-amd64]# ls
helm LICENSE README.md
[root@master linux-amd64]# cp helm /usr/local/bin/
[root@master linux-amd64]# cd
[root@master ~]#
[root@master ~]# helm --help
[root@master ~]# helm completion bash > ~/.helm
[root@master ~]# helm completion bash > ~/.helmrc
[root@master ~]# echo "source ~/.helmrc" >> ~/.bashrc
[root@master ~]# source ~/.bashrc
[root@master ~]# helm repo list
Error: no repositories to show
[root@master ~]# helm repo add azure http://mirror.azure.cn/kubernetes/charts/
"azure" has been added to your repositories
[root@master ~]# helm repo list
NAME URL
azure http://mirror.azure.cn/kubernetes/charts/
[root@master ~]# helm search repo mysql
NAME CHART VERSION APP VERSION DESCRIPTION
azure/mysql 1.6.9 5.7.30 DEPRECATED - Fast, reliable, scalable, and easy...
azure/mysqldump 2.6.2 2.4.1 DEPRECATED! - A Helm chart to help backup MySQL...
azure/prometheus-mysql-exporter 0.7.1 v0.11.0 DEPRECATED A Helm chart for prometheus mysql ex...
azure/percona 1.2.3 5.7.26 DEPRECATED - free, fully compatible, enhanced, ...
azure/percona-xtradb-cluster 1.0.8 5.7.19 DEPRECATED - free, fully compatible, enhanced, ...
azure/phpmyadmin 4.3.5 5.0.1 DEPRECATED phpMyAdmin is an mysql administratio...
azure/gcloud-sqlproxy 0.6.1 1.11 DEPRECATED Google Cloud SQL Proxy
azure/mariadb 7.3.14 10.3.22 DEPRECATED Fast, reliable, scalable, and easy t.
[root@master ~]# helm pull azure/mysql
[root@master ~]# ls
mysql-1.6.9.tgz
修改vlues.yaml
image: "registry.cn-hangzhou.aliyuncs.com/cloudcs/mysql"
imageTag: "888"
strategy:
type: Recreate
busybox:
image: "registry.cn-hangzhou.aliyuncs.com/tianhairui/busybox"
tag: "666"
testFramework关闭
testFramework:
enabled: false
mysql的root密码
## Default: random 10 character string
mysqlRootPassword: memeda
是否使用持久卷,改为false
## Persist data to a persistent volume
persistence:
enabled: false
关闭ssl
ssl:
enabled: false
[root@master ~]# helm install db mysql/
WARNING: This chart is deprecated
NAME: db
LAST DEPLOYED: Fri Aug 23 15:27:52 2024
NAMESPACE: abc
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
MySQL can be accessed via port 3306 on the following DNS name from within your cluster:
db-mysql.abc.svc.cluster.local
To get your root password run:
MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace abc db-mysql -o jsonpath="{.data.mysql-root-password}" | base64 --decode; echo)
To connect to your database:
1. Run an Ubuntu pod that you can use as a client:
kubectl run -i --tty ubuntu --image=ubuntu:16.04 --restart=Never -- bash -il
2. Install the mysql client:
$ apt-get update && apt-get install mysql-client -y
3. Connect using the mysql cli, then provide your password:
$ mysql -h db-mysql -p
To connect to your database directly from outside the K8s cluster:
MYSQL_HOST=127.0.0.1
MYSQL_PORT=3306
# Execute the following command to route the connection:
kubectl port-forward svc/db-mysql 3306
mysql -h ${MYSQL_HOST} -P${MYSQL_PORT} -u root -p${MYSQL_ROOT_PASSWORD}
[root@master ~]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
db-mysql-dc9795bbf-lh748 1/1 Running 0 46s 10.244.104.13 node2 <none> <none>
[root@master ~]# mysql -uroot -predhat -h 10.244.104.13
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 8.0.27 MySQL Community Server - GPL
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.003 sec)
MySQL [(none)]>
[root@master ~]# helm delete db
release "db" uninstalled
[root@master ~]# kubectl get pod
NAME READY STATUS RESTARTS AGE
db-mysql-dc9795bbf-lh748 0/1 Terminating 0 2m12s
[root@master ~]# kubectl get pod
No resources found in abc namespace.
CCE
云容器引擎 (Cloud Container Engine, CCE) 提供高性能可扩展的容器服务,基于云服务器快速构建高可靠的容器集群,深度整合网络和存储能力,兼容Kubernetes 及Docker 容器生态。帮助用户轻松创建和管理多样化的容器工作负载,并提供容器故障自愈,监控日志采集,自动弹性扩容等高效运维能力。
1. 创建CCE集群
2. 创建节点池
3. 扩容节点(添加节点)
4. 创建deploy,运行nginx,并绑定EIP可以对外提供访问
5. CCE里面创建一个wordpress博客