I have the following yaml
file creates a Kubernetes secret
for mysql
database.
apiVersion: v1
kind: Secret
metadata:
name: mysql-secret
key: MYSQL_KEY
type: Opaque
data:
mysql-root-password: 11111
mysql-user: a
mysql-password: 11111
But when I try to deploy it I get the following error:
- Error from server (BadRequest): error when creating "STDIN": Secret in version "v1" cannot be handled as a Secret: json: cannot unmarshal number into Go struct field Secret.data of type []uint8
What is the problem and how can I fix it?
EDIT
: The reason why do I added key: MY_SQL
field is because previously I could deploy mysql
on Kubernetes
cluster using the secret ke created by this command:
kubectl create secret generic mysql-secret --from-literal MYSQL_KEY=11111
And I wanted to produce the exact same output. I also need a MY_SQL
key to be able to connect to this pod from inside another pods like auth
pod that you can see it's deployment
file below:
apiVersion: apps/v1
kind: Deployment
metadata:
name: auth-depl
spec:
replicas: 1
selector:
matchLabels:
app: auth
template:
metadata:
labels:
app: auth
spec:
containers:
- name: auth
image: auth
env:
- name: MYSQL_URI
value: 'mysql://auth-mysql-srv:3306/users_auth'
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-secret
key: MYSQL_KEY