在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 小时前
玛卡巴卡的k8s知识点问答题(六)
云原生·容器·kubernetes
rider1892 小时前
【1】搭建k8s集群系列(二进制部署)之系统初始化
云原生·容器·kubernetes
小刘爱喇石( ˝ᗢ̈˝ )4 小时前
玛卡巴卡的k8s知识点问答题(七)
云原生·容器·kubernetes
小哈里5 小时前
【运维】云计算的发展历程,云原生时代的运维理念&工具技术栈,高可用系统的云运维 —— 以K8S集群调度算法与命令为例
运维·云原生·kubernetes·云计算·架构设计
{⌐■_■}5 小时前
【Kubernetes】如何使用 kubeadm 搭建 Kubernetes 集群?还有哪些部署工具?
云原生·容器·kubernetes
云上艺旅8 小时前
K8S学习之基础六十九:Rancher创建svc资源
学习·云原生·容器·kubernetes·rancher
可观测性用观测云21 小时前
Kubernetes APIServer 可观测最佳实践
kubernetes
碣石潇湘无限路1 天前
【云原生】Kubernetes CEL 速查表
容器·贪心算法·kubernetes
企鹅侠客1 天前
Prometheus operator怎么添加targets和告警规则
运维·云原生·kubernetes·prometheus·pod
Leo Han1 天前
k8s常用命令(持续更新中)
docker·容器·kubernetes