在K8s平台部署个人博客

在K8s平台部署个人博客

实验步骤

python 复制代码
kubectl create secret generic mysql-pass --from-literal=password=YOUR_PASSWORD

把mysql.tar.gz和wordpress.tar.gz上传到K8s工作节点,手动解压即可:

通过网盘分享的文件:wordpress.tar.gz

链接: https://pan.baidu.com/s/1nISFKNIyANvcuBAWE9MAMQ?pwd=u77k 提取码: u77k

通过网盘分享的文件:mysql.tar.gz

链接: https://pan.baidu.com/s/1NVw3fULvQ3NOAAKtjU7nOw?pwd=8r2v 提取码: 8r2v

python 复制代码
docker load -i mysql.tar.gz
docker load -i wordpress.tar.gz
ctr --n=k8s.io images import mysql.tar.gz
ctr --n=k8s.io images import wordpress.tar.gz

部署服务

python 复制代码
cat mysql.yaml
python 复制代码
apiVersion: v1
kind: Service
metadata:
  name: wordpress-mysql
  labels:
    app: wordpress
spec:
  ports:
    - port: 3306
  selector:
    app: wordpress
    tier: mysql
  clusterIP: None
---
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: wordpress-mysql
  labels:
    app: wordpress
spec:
  replicas: 1
  selector:
    matchLabels:
      app: wordpress
      tier: mysql
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: wordpress
        tier: mysql
    spec:
      containers:
      - image: mysql:5.6
        name: mysql
        env:
        - name: MYSQL_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mysql-pass
              key: password
        ports:
        - containerPort: 3306
          name: mysql
        volumeMounts:
        - name: mysql-persistent-storage
          mountPath: /var/lib/mysql
      volumes:
      - name: mysql-persistent-storage
        hostPath:
          path: /datawordpress
          type: DirectoryOrCreate
python 复制代码
cat wordpress.yaml
python 复制代码
apiVersion: v1
kind: Service
metadata:
  name: wordpress
  labels:
    app: wordpress
spec:
  type: NodePort
  ports:
    - port: 80
      nodePort: 30090
  selector:
    app: wordpress
    tier: frontend
---
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: wordpress
  labels:
    app: wordpress
spec:
  selector:
    matchLabels:
      app: wordpress
      tier: frontend
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: wordpress
        tier: frontend
    spec:
      containers:
      - image: wordpress:4.8-apache
        name: wordpress
        env:
        - name: WORDPRESS_DB_HOST
          value: wordpress-mysql
        - name: WORDPRESS_DB_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mysql-pass
              key: password
        ports:
        - containerPort: 80
          name: wordpress
        volumeMounts:
        - name: wordpress-persistent-storage
          mountPath: /var/www/html
      volumes:
      - name: wordpress-persistent-storage
        hostPath:
          path: /datamysqlwordpress
          type: DirectoryOrCreate
python 复制代码
kubectl apply -f mysql.yaml
kubectl apply -f wordpress.yaml

查看wordpress前端的service

python 复制代码
kubectl get svc -l app=wordpress
python 复制代码
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
wordpress NodePort 10.110.119.68 <none> 80:30090/TCP 36s
wordpress-mysql ClusterIP None <none> 3306/TCP 43s

浏览器访问http://node_ip:30090

相关推荐
起风了___2 小时前
Jenkins + Kubernetes 多模块微服务一键流水线:从 Maven 打包到滚动发布完整脚本
kubernetes·jenkins
2501_9418814015 小时前
Kubernetes 容器集群资源调度与弹性扩容高可用架构在互联网业务实战经验总结
云原生·容器·kubernetes
究極の法則に通じた野犬15 小时前
k8s设计理念-k8s中哪些服务要部署成StatefulSet哪些部署成Deployment
云原生·容器·kubernetes
wuxingge15 小时前
k8s集群误删node节点,怎么添加回去
云原生·容器·kubernetes
观测云18 小时前
Kubernetes CRD 方式配置容器日志采集最佳实践
容器·kubernetes·日志分析
运维-大白同学1 天前
2025最全面开源devops运维平台功能介绍
linux·运维·kubernetes·开源·运维开发·devops
敲上瘾1 天前
【探索实战】:Kurator分布式统一应用分发平台的全面解析与实践指南
分布式·容器·kubernetes·serverless
Connie14512 天前
记一次K8s故障告警排查(Grafna告警排查)
云原生·容器·kubernetes·grafana
谷隐凡二2 天前
Kubernetes主从架构简单解析:基于Python的模拟实现
python·架构·kubernetes
陈陈CHENCHEN2 天前
SuperMap iManager for K8s 离线环境镜像仓库 Containerd 部署
kubernetes