0
点赞
收藏
分享

微信扫一扫

CKAD备考之六——运行旧版应用程序

爱上流星雨 2024-03-11 阅读 7

运行旧版应用程序

[candidate@node-1] $ kubectl config use-context k8s
  1. 修复清单文件 /ckad/credible-mite/www.yaml 中的任何 API 弃用问题 以便可以将应用程序部署在 k8s cluster 上 。 注意:该应用程序是为 Kubernetes v1.15 开发的 。 k8s cluster 运行着 Kubernetes v1.26
  2. 请在 garfish namespace 中 部署 更新后的 清 单文件 /ckad/credible-mite/www.yaml 中指定的应用程序

解法:

# apiVersion应该是apps/v1,不是extensions/v1beta1
kubectl explain deployment.apiVersion
# 1.8版本之后 .spec.selector是required,不可省略,所以应该添加selector
kubectl explain deployment.spec
# 添加label的selector
kubectl explain deployment.spec.selector

image.png

vim /ckad/credible-mite/www.yaml
#/ckad/credible-mite/www.yaml
apiVersion: apps/v1 #修改
kind: Deployment
metadata:
  name: www-deployment
  namespace: garfish #添加namespace
spec:
  replicas: 1
  selector:         #添加
    matchLabels:    #添加
      app: nginx    #添加
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.16
        ports:
          - containerPort: 80
        volumeMounts:
          - mountPath: /var/log/nginx
            name: logs
        env:
          - name: NGINX_ENTRYPOINT_OUIET_LOGS
            value: "1"
      volumes:
        - name: logs
          emptyDir: {}
# 创建
kubectl apply -f /ckad/credible-mite/www.yaml
# 验证
kubectl get all -n garfish
举报

相关推荐

0 条评论