pod的环境变量使用,存活探针,就绪探针,资源限制和资源需求

举报
yd_266387056 发表于 2024/01/03 14:18:06 2024/01/03
【摘要】 1、创建MySQL Pod,使用环境变量初始化管理员密码、创建一个普通用户和一个数据库;kubectl create deployment mysql --image mysql:8.0 --dry-run=client -o yaml > mysql1.yamlapiVersion: apps/v1kind: Deploymentmetadata: creationTimestamp: ...
1、创建MySQL Pod,使用环境变量初始化管理员密码、创建一个普通用户和一个数据库;
kubectl create deployment mysql --image mysql:8.0 --dry-run=client -o yaml > mysql1.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: mysql
  name: mysql
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mysql
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: mysql
    spec:
      containers:
      - image: mysql:8.0
        name: mysql
        env:
        - name: MYSQL_RANDOM_ROOT_PASSWORD
          value: '1'
        - name: MYSQL_DATABASE
          value: 'wordpress'
        - name: MYSQL_USER
          value: 'wpuser'          
        resources: {}
status: {}

root@k8s-master01:~/wordpress#kubectl apply -f mysql1.yaml
2、创建wordpress Pod,使用环境变量对接到MySQL,并wordpress初始化;
kubectl create deployment wordpress --image wordpress:5.7 --dry-run=client -o yaml > wordpress.yaml

root@k8s-master01:~/wordpress# vim wordpress.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: wordpress
  name: wordpress
spec:
  replicas: 1
  selector:
    matchLabels:
      app: wordpress
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: wordpress
    spec:
      containers:
      - image: wordpress:5.7
        name: wordpress
          #        livenessProbe:
          #httpGet:
          #  path: '/'
          #  scheme: HTTP
        env:
        - name: WORDPRESS_DB_HOST
          value: '10.244.3.56'
        - name: WORDPRESS_DB_NAME
          value: 'wordpress'
        - name: WORDPRESS_DB_USER
          value: 'wpuser'
        - name: WORDPRESS_DB_PASSWORD
          value: '123456'
        ports:
        - containerPort: 80
          hostPort: 8080

        resources: {}
status: {}

root@k8s-master01:~/wordpress#kubectl apply -f wordpress.yaml
3、为以上Pod设定livenessProbe, readinessProbe, resource limits和resource requests。
#mysql
apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: mysql
  name: mysql
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mysql
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: mysql
    spec:
      containers:
      - image: mysql:8.0
        name: mysql
        readinessProbe:
          exec:
            command: ['/bin/sh', '-c', '/usr/bin/mysql -u wpuser -p123456']
          initialDelaySeconds: 10
          timeoutSeconds: 5
          periodSeconds: 5
          failureThreshold: 10
        livenessProbe:
          tcpSocket:
            port: 3306
          initialDelaySeconds: 10
          timeoutSeconds: 5
          periodSeconds: 5
          failureThreshold: 5
        env:
        - name: MYSQL_RANDOM_ROOT_PASSWORD
          value: '1'
        - name: MYSQL_DATABASE
          value: 'wordpress'
        - name: MYSQL_USER
          value: 'wpuser'                              
        resources:
          requests:
            memory: "64Mi"
            cpu: "200m"
          limits:
            memory: "512Mi"
            cpu: "1"
status: {}


#wordpress
apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: wordpress
  name: wordpress
spec:
  replicas: 1
  selector:
    matchLabels:
      app: wordpress
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: wordpress
    spec:
      containers:
      - image: wordpress:5.7
        name: wordpress
        livenessProbe:
          httpGet:
            path: '/'
            port: 80
            scheme: HTTP
          intialDelaySeconds: 3
          timeoutSeconds: 2           
        readnessProbe:
          httpGet:
            path: '/'
            port: 80
            scheme: HTTP
          intialDelaySeconds: 15
          timeoutSeconds: 2
        restartPolicy: Always              
        env:
        - name: WORDPRESS_DB_HOST
          value: '10.244.3.56'
        - name: WORDPRESS_DB_NAME
          value: 'wordpress'
        - name: WORDPRESS_DB_USER
          value: 'wpuser'
        - name: WORDPRESS_DB_PASSWORD
          value: '123456'
        ports:
        - containerPort: 80
          hostPort: 8080

        resources:
          requests:
            memory: "90Mi"
            cpu: "1"
          limits:
            memory: "300Mi"
            cpu: "1
status: {}
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。