Kubernetes Dashboard

接前话,仍然“只准备 1 个 server 节点和 3 个 agent 节点”,非高可用 K3s 集群

创建配置文件

创建 MySQL Deployment

mysql-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql
spec:
  selector:
    matchLabels:
      app: mysql
  replicas: 1
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
      - name: mysql
        image: mysql:8.4.2
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: "yourpassword"
        ports:
        - containerPort: 3306

创建 MySQL Service

mysql-service.yaml

apiVersion: v1
kind: Service
metadata:
  name: mysql
spec:
  ports:
  - port: 3306
  selector:
    app: mysql
  clusterIP: None

部署 MySQL

使用 kubectl 命令将上述配置应用到 K3s 集群中

kubectl apply -f mysql-deployment.yaml
kubectl apply -f mysql-service.yaml

验证部署

使用以下命令来验证 MySQL 是否成功部署

kubectl get pods
kubectl get svc
root@k3s-master:~# kubectl get pods
NAME                     READY   STATUS    RESTARTS   AGE
mysql-8488594b75-gjntt   1/1     Running   0          15s
root@k3s-master:~# kubectl get svc
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)    AGE
kubernetes   ClusterIP   10.43.0.1    <none>        443/TCP    12m
mysql        ClusterIP   None         <none>        3306/TCP   14s

进入 MySQL pod

root@k3s-master:~# kubectl exec -it mysql-8488594b75-gjntt -- /bin/bash
bash-5.1# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.4.2 MySQL Community Server - GPL

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

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 clear the current input statement.

mysql> 
mysql> quit
Bye

参考资料

此文章仍未完结,等待补充

最后修改:2024 年 09 月 09 日
如果觉得我的文章对你有用,请随意赞赏