在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

相关推荐
昌sit!3 小时前
K8S node节点没有相应的pod镜像运行故障处理办法
云原生·容器·kubernetes
A ?Charis6 小时前
Gitlab-runner running on Kubernetes - hostAliases
容器·kubernetes·gitlab
北漂IT民工_程序员_ZG7 小时前
k8s集群安装(minikube)
云原生·容器·kubernetes
2301_8061313613 小时前
Kubernetes的基本构建块和最小可调度单元pod-0
云原生·容器·kubernetes
SilentCodeY14 小时前
containerd配置私有仓库registry
容器·kubernetes·containerd·镜像·crictl
binqian20 小时前
【k8s】ClusterIP能http访问,但是不能ping 的原因
http·容器·kubernetes
探索云原生21 小时前
GPU 环境搭建指南:如何在裸机、Docker、K8s 等环境中使用 GPU
ai·云原生·kubernetes·go·gpu
是垚不是土1 天前
Istio流量镜像测试
运维·kubernetes·云计算·istio
蚊子不吸吸1 天前
DevOps开发运维简述
linux·运维·ci/cd·oracle·kubernetes·gitlab·devops
林小果11 天前
K8S搭建
云原生·容器·kubernetes