openshift 中oc get pod 找不到pod (附一些检查command)

今天练习通过yaml 文件来创建pod (application 应用), 参考的link 是:

https://www.cnblogs.com/xcmelody/p/11382976.html

还是先贴一下代码:(注意: 和上面link 中代码有改动)

[root@test3 scripts]# cat nginx.yaml 
apiVersion: v1 
items:
- apiVersion: v1     #apps.openshift.io/v1
  # okd 部署配置(dc),与 k8s Deployment 资源对象类似,以启动多个容器的方式生成 pod
  kind: DeploymentConfig
  metadata:
    # 标签,在查询时具体资源对象时非常重要,如:>oc get dc -l app=nginx
    labels:
      app: nginx
    name: nginx
    # 选定项目空间
    namespace: xinxin
  spec:
    # 副本数,即 nginx app 部署的实例数
    replicas: 1
    # pod 的计算资源配额
    resources:
      # pod 能分配的最大计算资源
      limits:
        cpu: 300m
        memory: 1024Mi
      # pod 分配的最少计算资源
      requests:
        cpu: 100m
        memory: 200Mi
    # 选择器 Service 根据此项来绑定到 dc
    selector:
      name: nginx
    strategy:
    #   type: Recreate
      type: Rolling
    # dc 根据模板里内容创建 pod
    template:
      metadata:
        labels:
          app: nginx
          name: nginx
          deploymentconfig: nginx
      spec:
        # 容器集合
        containers:
        - capabilities: {}
          # 容器内环境变量,下文给这个容器设置了时区和语言的环境变量
          env:
          - name: TZ
            value: Asia/Shanghai
          - name: LANG
            value: en_US.UTF-8
          # 容器使用什么镜像部署,在创建时需要替换成实际要部署的镜像
          image: nginx:1.16
          # 镜像下载策略,总是下载最新的(Always)
          imagePullPolicy: IfNotPresent
          ports: 
            - containerPort: 80
              protocol: TCP          

          # 健康检查-pod 是否存活
          livenessProbe:
            failureThreshold: 2
            # http get 请求的方式验证 pod-ip:80/
            httpGet:
              path: /
              port: 80
            initialDelaySeconds: 60
            periodSeconds: 60
            timeoutSeconds: 5
          name: nginx
          # 健康检查-pod 是否就绪
          readinessProbe:
            httpGet:
              path: /
              port: 80
            initialDelaySeconds: 3
            timeoutSeconds: 5
          # 容器计算资源配额,与 pod 配额类似
          resources:
            limits:
              cpu: 300m
              memory: 1024Mi
            requests:
              cpu: 100m
              memory: 200Mi
          securityContext:
            capabilities: {}
            # privileged: true
          terminationMessagePath: /dev/termination-log
          # 将 pod 中配置的卷挂载到容器内
        #   volumeMounts:
        #   - mountPath: /data
        #     name: nginx
        dnsPolicy: ClusterFirst
        # 使用节点选择器将应用固定部署到 node1 计算节点上
        # nodeSelector:
        #   kubernetes.io/hostname: node1.app.com
        restartPolicy: Always
        # 配置和定义使用实际计算节点主机文件夹地址这种类型的卷
        # volumes:
        # - persistentVolumeClaim:
        #     claimName: nginx
        #   name: nginx
    # pod 触发器--配置变动触发更新
    triggers:
    - type: ConfigChange
- apiVersion: v1
  # 服务,与 k8s 中 service 一样,将 dc 上部署的应用暴露给内部(多)或外部(少)
  kind: Service
  metadata:
    labels:
      app: nginx
    name: nginx
  spec:
    # 应用中要暴露的端口信息
    ports:
    - name: http
      # 对外暴露的端口
      port: 80
      protocol: TCP
      # 应用实际端口
      targetPort: 80
    # 通过选择器选择 dc
    selector:
      name: nginx
    sessionAffinity: None
    type: ClusterIP
    
kind: List
metadata: {}
--------------

注意:有openshift 版本的问题,apiVersion: 有的是V1, 有的需要改变,如果按照:apiVersion: apps.openshift.io/v1

报错:error: unable to recognize apps.openshift.io/v1, Kind=DeploymentConfig: no matches for apps.openshift.io/, Kind=DeploymentConfig

解决方法: 把apiVersion 改成 V1 就可以了。

好,下面按照nginx 的yaml 文件,执行:

oc create -f nginx.yaml 
deploymentconfig "nginx" created
service "nginx" created
发现pod 已经执行好了,查看一下: 

[root@test3 scripts]# oc get pod
NAME                      READY     STATUS             RESTARTS   AGE
 

发现怎么找不到呢?

原来这个ID 登入进入: 有几个project:

[root@test3 scripts]# oc get project
NAME      DISPLAY NAME   STATUS
shp                      Active
xinxin                   Active
[root@test3 scripts]# 

OK, 下面到xinxin project 下面看看:

[root@test3 scripts]# oc project xinxin
Already on project "xinxin" on server "https://localhost:8443".
[root@test3 scripts]# 

[root@test3 scripts]# oc get pod
NAME                       READY     STATUS               RESTARTS   AGE
nginx-1-deploy             0/1       ContainerCannotRun   0          16m
 

可以看到nginx 这个pod 已经创建好了,虽然这个container 有小问题,下面看一下log:

[root@test3 scripts]# oc describe pod nginx-1-deploy
-----------

对于一些dc (deployment config) 可以检查一下:

[root@test3 scripts]# oc get dc
NAME              REVISION   DESIRED   CURRENT   TRIGGERED BY
hello-openshift   1          1         0         config
nginx             1          1         0         config
可以看一看这些具体的yaml 配置:

[root@test3 scripts]# oc get dc -o yaml
 

(openshift 的project 的name 和yaml 文件中对应的namespace 要一致的,可以看上面的yaml 文件中的xinxin)

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

shenghuiping2001

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值