Programming/Kubernetes

K8S - Wordpress, MySQL (yml 파일) 생성 후 배포

잇(IT) 2022. 7. 27. 10:49

- Wordpress, MySQL 파일 작성

apiVersion: apps/v1
kind: Deployment
metadata:
  name: wordpress-mysql
  labels:
    app: wordpress
spec:
  selector:
    matchLabels:
      app: wordpress
      tier: mysql
  template:
    metadata:
      labels:
        app: wordpress
        tier: mysql
    spec:
      containers:
        - image: mariadb:10.7
          name: mysql
          env:
            - name: MYSQL_DATABASE
              value: wordpress
            - name: MYSQL_ROOT_PASSWORD
              value: password
          ports:
            - containerPort: 3306
              name: mysql

---
apiVersion: v1
kind: Service
metadata:
  name: wordpress-mysql
  labels:
    app: wordpress
spec:
  ports:
    - port: 3306
  selector:
    app: wordpress
    tier: mysql

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: wordpress
  labels:
    app: wordpress
spec:
  selector:
    matchLabels:
      app: wordpress
      tier: frontend
  template:
    metadata:
      labels:
        app: wordpress
        tier: frontend
    spec:
      containers:
        - image: wordpress:5.9.1-php8.1-apache
          name: wordpress
          env:
            - name: WORDPRESS_DB_HOST
              value: wordpress-mysql
            - name: WORDPRESS_DB_NAME
              value: wordpress
            - name: WORDPRESS_DB_USER
              value: root
            - name: WORDPRESS_DB_PASSWORD
              value: password
          ports:
            - containerPort: 80
              name: wordpress

---
apiVersion: v1
kind: Service
metadata:
  name: wordpress
  labels:
    app: wordpress
spec:
  type: NodePort
  ports:
    - port: 80
  selector:
    app: wordpress
    tier: frontend

- 위와 같이 yml 파일을 작성한다.

 

 

kubectl apply -f wordpress-k8s.yml

- 위에서 생성한 파일을 apply로 실행

 

kubectl get all

- kubectl get all 명령어로 확인 후 service/wordpress에 해당하는 컨테이너의 포트번호(32029)를 확인한다.

- [master ip]:[wordpress port] = 10.0.0.1:32029로 접속 시도한다.

 

- 위와 같이 정상적으로 wordpress가 실행되는 것을 확인 할 수 있다.

728x90

'Programming > Kubernetes' 카테고리의 다른 글

K8S - Deployment  (0) 2022.07.28
K8S - Replicaset  (0) 2022.07.27
K8S - Deployment, Replicas, pods 생성  (0) 2022.07.26
K8S - pod describe 정보  (0) 2022.07.26
K8S - yml 파일을 이용한 pod 생성  (0) 2022.07.25