|
23 | 23 | ```
|
24 | 24 | kubectl apply -k https://github.com/nakamasato/mysql-operator/config/mysql
|
25 | 25 | ```
|
26 |
| -1. Apply custom resources (`MySQL`, `MySQLUser`, `MySQLDB`). |
27 | 26 |
|
28 |
| - `mysql.yaml` credentials to connect to the MySQL: |
| 27 | +1. Configure MySQL credentials for the operator using the custom resources `MySQL`. |
| 28 | +
|
| 29 | + `mysql.yaml` credentials to connect to the MySQL: **This user is used to manage MySQL users and databases, which is ususally an admin user.** |
29 | 30 |
|
30 | 31 | ```yaml
|
31 | 32 | apiVersion: mysql.nakamasato.com/v1alpha1
|
|
42 | 43 | type: raw
|
43 | 44 | ```
|
44 | 45 |
|
| 46 | + If you installed mysql sample with the command above, the password for the root user is `password`. You can apply `MySQL` with the following command. |
| 47 | +
|
| 48 | + ``` |
| 49 | + kubectl apply -f https://raw.githubusercontent.com/nakamasato/mysql-operator/main/config/samples-on-k8s/mysql_v1alpha1_mysql.yaml |
| 50 | + ``` |
| 51 | +
|
| 52 | + You can check the `MySQL` object and status: |
| 53 | +
|
| 54 | + ``` |
| 55 | + kubectl get mysql |
| 56 | + NAME HOST ADMINUSER CONNECTED USERCOUNT DBCOUNT REASON |
| 57 | + mysql-sample mysql.default root true 0 0 Ping succeded and updated MySQLClients |
| 58 | + ``` |
| 59 | +
|
| 60 | +1. Create a new MySQL user with custom resource `MySQLUser`. |
| 61 | +
|
45 | 62 | `mysqluser.yaml`: MySQL user
|
46 | 63 |
|
47 | 64 | ```yaml
|
|
54 | 71 | host: '%'
|
55 | 72 | ```
|
56 | 73 |
|
| 74 | + 1. Create a new MySQL user `nakamasato` |
| 75 | +
|
| 76 | + ``` |
| 77 | + kubectl apply -f https://raw.githubusercontent.com/nakamasato/mysql-operator/main/config/samples-on-k8s/mysql_v1alpha1_mysqluser.yaml |
| 78 | + ``` |
| 79 | +
|
| 80 | + 1. You can check the status of `MySQLUser` object |
| 81 | +
|
| 82 | + ``` |
| 83 | + kubectl get mysqluser |
| 84 | + NAME MYSQLUSER SECRET PHASE REASON |
| 85 | + nakamasato true true Ready Both secret and mysql user are successfully created. |
| 86 | + ``` |
| 87 | +
|
| 88 | + 1. You can also confirm the Secret for the new MySQL user is created. |
| 89 | +
|
| 90 | + ``` |
| 91 | + kubectl get secret |
| 92 | + NAME TYPE DATA AGE |
| 93 | + mysql-mysql-sample-nakamasato Opaque 1 4m3s |
| 94 | + ``` |
| 95 | +
|
| 96 | + 1. Connect to MySQL with the newly created user |
| 97 | +
|
| 98 | + ``` |
| 99 | + kubectl exec -it $(kubectl get po | grep mysql | head -1 | awk '{print $1}') -- mysql -unakamasato -p$(kubectl get secret mysql-mysql-sample-nakamasato -o jsonpath='{.data.password}' | base64 --decode) |
| 100 | + ``` |
| 101 | +
|
| 102 | +1. Create a new MySQL database with custom resource `MySQLDB`. |
| 103 | +
|
57 | 104 | `mysqldb.yaml`: MySQL database
|
58 | 105 |
|
59 | 106 | ```yaml
|
|
67 | 114 | ```
|
68 | 115 |
|
69 | 116 | ```
|
70 |
| - kubectl apply -k https://github.com/nakamasato/mysql-operator/config/samples-on-k8s |
| 117 | + kubectl apply -f https://raw.githubusercontent.com/nakamasato/mysql-operator/main/config/samples-on-k8s/mysql_v1alpha1_mysqldb.yaml |
| 118 | + ``` |
| 119 | +
|
| 120 | + ``` |
| 121 | + kubectl get mysqldb |
| 122 | + NAME PHASE REASON SCHEMAMIGRATION |
| 123 | + sample-db Ready Database successfully created {"dirty":false,"version":0} |
71 | 124 | ```
|
72 |
| -1. Check `MySQLUser` and `Secret` for the MySQL user |
| 125 | +
|
| 126 | +1. Grant all priviledges of the created db (`sample_db`) to the create user (`nakamasato`) (TODO: Currently there's no way to manage user permissions with operator.) |
73 | 127 |
|
74 | 128 | ```
|
75 |
| - kubectl get mysqluser |
76 |
| - NAME PHASE REASON |
77 |
| - nakamasato Ready Both secret and mysql user are successfully created. |
| 129 | + kubectl exec -it $(kubectl get po | grep mysql | head -1 | awk '{print $1}') -- mysql -uroot -ppassword |
78 | 130 | ```
|
79 | 131 |
|
| 132 | + ```sql |
| 133 | + GRANT ALL PRIVILEGES ON sample_db.* TO 'nakamasato'@'%'; |
80 | 134 | ```
|
81 |
| - kubectl get secret |
82 |
| - NAME TYPE DATA AGE |
83 |
| - mysql-mysql-sample-nakamasato Opaque 1 10s |
| 135 | +
|
| 136 | + Now the created user got the permission to use `sample_db`. |
| 137 | +
|
84 | 138 | ```
|
85 |
| -1. Connect to MySQL with the secret |
| 139 | + ubectl exec -it $(kubectl get po | grep mysql | head -1 | awk '{print $1}') -- mysql -unakamasato -p$(kubectl get secret mysql-mysql-sample-nakamasato -o jsonpath='{.data.password}' | base64 --decode) |
86 | 140 | ```
|
87 |
| - kubectl exec -it $(kubectl get po | grep mysql | head -1 | awk '{print $1}') -- mysql -unakamasato -p$(kubectl get secret mysql-mysql-sample-nakamasato -o jsonpath='{.data.password}' | base64 --decode) |
| 141 | +
|
| 142 | + ``` |
| 143 | + mysql> show databases; |
| 144 | + +--------------------+ |
| 145 | + | Database | |
| 146 | + +--------------------+ |
| 147 | + | information_schema | |
| 148 | + | performance_schema | |
| 149 | + | sample_db | |
| 150 | + +--------------------+ |
| 151 | + 3 rows in set (0.00 sec) |
88 | 152 | ```
|
| 153 | +
|
89 | 154 | 1. Delete custom resources (`MySQL`, `MySQLUser`, `MySQLDB`).
|
90 | 155 | Example:
|
91 | 156 | ```
|
|
0 commit comments