今天搭配k8s时遇到一问题:在配置文件时,尝试修改yaml配置文件内容namespace:kube-system,
结果却导致在master处无法查询到已创建的pod,但可以在节点查询到docker实例已生成。
完整配置如下:

kind: ReplicationController
apiVersion: v1
metadata:
  name: mysql
  namespace: kube-system
spec:
  replicas: 1
  selector:
    name: mysql
  template:
    metadata:
      labels:
        name: mysql
    spec:
      containers:
      - name: mysql
        image: docker.io/mysql/mysql-server
        ports:
        - containerPort: 3306
          protocol: TCP
        env:
          - name: MYSQL_ROOT_PASSWORD
            value: "hello123"

然后创建pod:

[root@master ~]# kubectl create -f mysql-deployment.yaml 
replicationcontroller "mysql" created

然而用kubectl get pod 命令却无法查看到 pod的存在:

[root@master ~]# kubectl get pod
No resources found.

在pod节点却可以发现有docker已经在运行:

[root@node1 ~]# docker ps
CONTAINER ID        IMAGE                                   COMMAND                  CREATED             STATUS                   PORTS               NAMES
4cdc3097cbdc        docker.io/mysql/mysql-server            "/entrypoint.sh my..."   2 minutes ago       Up 2 minutes (healthy)                       k8s_mysql.3b8a259e_mysql-5grrg_kube-system_81b528e7-b102-11e9-83a1-000c2967b610_422ef39f
d34cd25a1931        docker.io/tianyebj/pod-infrastructure   "/pod"                   2 minutes ago       Up 2 minutes                                 k8s_POD.57ea03a4_mysql-5grrg_kube-system_81b528e7-b102-11e9-83a1-000c2967b610_86ff2ce7

遂猜想,kube-system类型的pod在默认“default”命令下无法看到:
遂添加指定类型参数查询:

[root@master ~]# kubectl get pods -n kube-system 
NAME          READY     STATUS    RESTARTS   AGE
mysql-5grrg   1/1       Running   0          4m

果然可以发现此pod,如想删除也需添加指定类型参数即可:

[root@master ~]# kubectl delete rc -n kube-system mysql(因为我的配置文件内设定:replicas为1,即会自动创建副本,无法用kubectl delete pod 删除)
replicationcontroller "mysql" deleted

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐