把外部的服务,通过创建service和endpoint,把它映射到k8s内部来使用。
操作步骤:
在10.0.0.13上安装数据库
yum install mariadb-server -y
systemctl start mariadb.service
systemctl enable mariadb,service
创建数据库的安全初始化
mysql_secure_installation
先回车,再选n,一路y
根据原配置,创建数据库
mysql #进入数据库
创建数据库
create database wrodpress;
创建远程连接用户
grant all on wordpress.* to wordpress@'%' identified by 'wordpress';
yml文件
[root@k8s-master wordpress]# cat mysql-ep.yml
apiVersion: v1
kind: Endpoints
metadata:
name: mysql-wp
namespace: wordpress
subsets:
- addresses:
- ip: 10.0.0.13
ports:
- port: 3306
protocol: TCP
`[root@k8s-master wordpress]# cat mysql-svc.yml apiVersion: v1 kind: Service metadata: namespace: wordpress name: mysql-wp spec: ports: - port: 3306 targetPort: 3306
[root@k8s-master wordpress]# cat wordpress-rc.yml
apiVersion: v1
kind: ReplicationController
metadata:
namespace: wordpress
name: wordpress
spec:
replicas: 1
selector:
app: wordpress
template:
metadata:
labels:
app: wordpress
spec:
volumes:
- name: wordpress-web
nfs:
path: /data/wordpress-web
server: 10.0.0.11
containers:
- name: wordpress
image: 10.0.0.11:5000/wordpress:latest
ports:
- containerPort: 80
volumeMounts:
- mountPath: /var/www/html
name: wordpress-web
env:
- name: WORDPRESS_DB_HOST
value: 'mysql-wp'
- name: WORDPRESS_DB_USER
value: 'wordpress'
- name: WORDPRESS_DB_PASSWORD
value: 'wordpress'
[root@k8s-master wordpress]# cat wordpress-svc.yml
apiVersion: v1
kind: Service
metadata:
namespace: wordpress
name: wordpress
spec:
type: NodePort
ports:
- port: 80
nodePort: 30009
selector:
app: wordpress
```
创建
kubectl create -f .
打开网页验证