日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > 数据库 >内容正文

数据库

coreos 安装 mysql_kubernetes下安装mysql

發(fā)布時(shí)間:2025/3/15 数据库 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 coreos 安装 mysql_kubernetes下安装mysql 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

注:有mysql安裝在k8s集群內(nèi),集群外且通過(guò)k8s service endpoint代理外部mysql服務(wù)供內(nèi)k8s內(nèi)部集群訪問(wèn)兩種方式,本文為第二種

一,先在k8s-node上docker安裝mysql,并遠(yuǎn)程連接可用

1.下載mysql鏡像

[root@k8s-node1 ~]# docker pull mysql:5.7

5.7: Pulling from library/mysql

27833a3ba0a5: Pull complete

864c283b3c4b: Pull complete

cea281b2278b: Pull complete

8f856c14f5af: Pull complete

9c4f38c23b6f: Pull complete

1b810e1751b3: Pull complete

5479aaef3d30: Pull complete

1d924ec3d520: Pull complete

1ab7ae63ac60: Pull complete

08aa5f3680e9: Pull complete

a832d0a0972a: Pull complete

Digest: sha256:dba5fed182e64064b688ccd22b2f9cad4ee88608c82f8cff21e17bab8da72b81

Status: Downloaded newer imagefor mysql:5.7[root@k8s-node1 ~]# docer images-bash: docer: 未找到命令

[root@k8s-node1 ~]# docker images

REPOSITORY TAG IMAGE ID CREATED SIZE

mytomcat v8 f1332ae3f57012days ago 463MB

mytomcat v9 f1332ae3f57012days ago 463MB

tomcat8 f1332ae3f570 12days ago 463MB

mysql5.7 98455b9624a9 2weeks ago 372MB

k8s.gcr.io/kube-proxy v1.14.0 5cd54e388aba 2 weeks ago 82.1MB

k8s.gcr.io/kube-controller-manager v1.14.0 b95b1efa0436 2weeks ago 158MB

k8s.gcr.io/kube-scheduler v1.14.0 00638a24688b 2 weeks ago 81.6MB

k8s.gcr.io/kube-apiserver v1.14.0 ecf910f40d6e 2weeks ago 210MB

quay.io/coreos/flannel v0.11.0-amd64 ff281650a721 2 months ago 52.6MB

k8s.gcr.io/coredns 1.3.1 eb516548c180 2 months ago 40.3MB

k8s.gcr.io/etcd 3.3.10 2c4adeb21b4f 4months ago 258MB

k8s.gcr.io/pause 3.1 da86e6ba6ca1 15months ago 742kB

[root@k8s-node1 ~]#

2.啟動(dòng),-v

[root@k8s-node1 mysql]# docker run -d -p 3306:3306 -v /var/local/mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=mysql --name docker-mysql mysql:5.787b7410ea379136b3743e194bb312b1bb6fe02abe73e706e04c68856aecc507a

[root@k8s-node1 mysql]#

進(jìn)入mysql container

[root@k8s-node1 mysql]# docker ps -a

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

87b7410ea379 mysql:5.7 "docker-entrypoint.s…" About a minute ago Up About a minute 0.0.0.0:3306->3306/tcp, 33060/tcp docker-mysql[root@k8s-node1 mysql]# docker exec -it 87b7410ea379 /bin/bash

root@87b7410ea379:/# mysql -uroot -pmysql

mysql: [Warning] Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connectionid is 2Server version:5.7.25MySQL Community Server (GPL)

Copyright (c)2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type'help;' or '\h' for help. Type '\c' to clearthe current input statement.

mysql>

mysql> exit

Bye

root@87b7410ea379:/# exit

exit

[root@k8s-node1 mysql]#

3.遠(yuǎn)程連接

二,到k8s master創(chuàng)建server,endpoint代理訪問(wèn)

1.到k8s-master上驗(yàn)證是否可以連接,前提是已安裝mysql客戶端(如果沒(méi)有centos7安裝mysql客戶端)

[root@k8s-master master]# mysql -h192.168.111.131 -P3306 -uroot -pmysql

Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MySQL connectionid is 12Server version:5.7.25MySQL Community Server (GPL)

Copyright (c)2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type'help;' or '\h' for help. Type '\c' to clearthe current input statement.

MySQL [(none)]>exit

Bye

[root@k8s-master master]#

2.創(chuàng)建mysql-out.svc.yaml文件

[root@k8s-master ~]# cat mysql-out-svc.yaml

apiVersion: v1

kind: Service

metadata:

name: mysql-out-svc

spec:

ports:- port: 3306protocol: TCP

targetPort:3306

---apiVersion: v1

kind: Endpoints

metadata:

name: mysql-out-svc

subsets:-addresses:- ip: "192.168.111.131"ports:- port: 3306[root@k8s-master ~]#

在service中,各項(xiàng)配置意義

spec:

type: NodePort????? #這里代表是NodePort類型的,另外還有ingress,LoadBalancer

ports:

- port: 80????????? #這里的端口和clusterIP(kubectl describe service service-hello中的IP的port)對(duì)應(yīng),即在集群中所有機(jī)器上curl 10.98.166.242:80可訪問(wèn)發(fā)布的應(yīng)用服務(wù)。

targetPort: 8080? #端口一定要和container暴露出來(lái)的端口對(duì)應(yīng),nodejs暴露出來(lái)的端口是8081,所以這里也應(yīng)是8081

protocol: TCP

nodePort: 31111?? # 所有的節(jié)點(diǎn)都會(huì)開(kāi)放此端口,此端口供外部調(diào)用。

selector:

run: hello???????? #這里選擇器一定要選擇容器的標(biāo)簽,之前寫name:kube-node是錯(cuò)的。

3.啟動(dòng)service

[root@k8s-master ~]# kubectl create -f mysql-out-svc.yaml

service/mysql-out-svc created

endpoints/mysql-out-svc created

[root@k8s-master ~]# kubectl get services -o wide

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR

kubernetes ClusterIP10.96.0.1 443/TCP 8d mysql-out-svc ClusterIP 10.111.241.185 3306/TCP 18s service-hello NodePort 10.98.166.242 80:31111/TCP 8d run=hello

[root@k8s-master ~]# kubectl get endpoints -o wide

NAME ENDPOINTS AGE

kubernetes192.168.111.130:64438d

mysql-out-svc 192.168.111.131:330637s

service-hello 10.244.1.36:8080,10.244.1.37:8080 8d

因?yàn)槭褂玫氖莐8s集群外部mysql服務(wù),然后用service代理,讓k8s集群內(nèi)的其它service(如service-hello)可通過(guò) cluster-ip:port(10.111.241.185:3306)來(lái)訪問(wèn)外部的mysql服務(wù)

所以此外并沒(méi)有生成mysql?的pod

[root@k8s-master ~]# kubectl get pods -o wide

NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES

hello-5cd4456b66-gstq6 1/1 Running 1 7d17h 10.244.1.36 k8s-node1 hello-5cd4456b66-sb5px 1/1 Running 1 7d17h 10.244.1.37 k8s-node1

4.在k8s-master上也可以通過(guò)?cluster-ip:port(10.111.241.185:3306)來(lái)訪問(wèn)外部的mysql服務(wù)

[root@k8s-master ~]# mysql -h10.111.241.185 -P3306 -uroot -pmysql

Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MySQL connectionid is 13Server version:5.7.25MySQL Community Server (GPL)

Copyright (c)2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type'help;' or '\h' for help. Type '\c' to clearthe current input statement.

MySQL [(none)]>

到此,k8s上安裝msyql完成

總結(jié)

以上是生活随笔為你收集整理的coreos 安装 mysql_kubernetes下安装mysql的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。