Cluster IP Setup:
ClusterIP is the default ServiceType. A Service gets its Virtual IP address using the ClusterIP. That IP address is used for communicating with the Service and is accessible only within the cluster.
# vim mysql.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql
spec:
replicas: 1
selector:
matchLabels:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
containers:
- name: mysql
image: mysql:latest
ports:
- containerPort: 3306
env:
- name: MYSQL_ROOT_PASSWORD
value: shashi123
- name: MYSQL_DATABASE
value: test
- name: MYSQL_USER
value: test
- name: MYSQL_PASSWORD
value: test123
# kubectl apply -f mysql.yaml
# vim mysql-service.yaml
apiVersion: v1
kind: Service
metadata:
name: mysql-service
spec:
selector:
app: mysql
ports:
- protocol: TCP
port: 3306
targetPort: 3306
type: ClusterIP
# kubectl get all
How to check container IP.
# kubectl describe pods mysql-77b47f887-8tjgl
# kubectl apply -f mysql-service.yaml
# kubectl get pods
# kubectl exec mysql-77b47f887-8tjgl -it bash
# echo "default_authentication_plugin=mysql_native_password" >> etc/my.cnf
bash-4.4# mysql -u root -p
ALTER USER 'test'@'%' IDENTIFIED WITH mysql_native_password BY 'test123';
# kubectl get svc mysql-service
# kubectl get endpoints
Test DB
# mysql -h 10.104.214.185 -u test -p3306 -p
No comments:
Post a Comment