Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3759776
  • 博文数量: 880
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 6155
  • 用 户 组: 普通用户
  • 注册时间: 2016-11-11 09:12
个人简介

To be a better coder

文章分类

全部博文(880)

文章存档

2022年(5)

2021年(60)

2020年(175)

2019年(207)

2018年(210)

2017年(142)

2016年(81)

分类: LINUX

2020-01-13 15:12:24

MiniKubeerror in validating replica set:ValidationError(ReplicaSet.spec.template.metadata):unknown field“spec” in io.k8s.apimachinery.pkg.apis.meta.v1

问题,格式参数不对
kind: Deployment
metadata:
  name: my-nginx
spec:
  selector:
    matchLabels:
      app: my-nginx

no matches for kind "Deployment" in version "extensions/v1beta1"

0x00 Problem

[root@k8sm90 demo]# kubectl create -f tomcat-deployment.yaml error: unable to recognize "tomcat-deployment.yaml": no matches for kind "Deployment" in version "extensions/v1beta1"

0x01 Solution

修改 apiVersion 选项: apps/v1

[root@k8sm90 demo]# cat tomcat-deployment.yaml apiVersion: apps/v1 kind: Deployment ...

因为我的 k8s 版本是 1.16.2,在这个版本中 Deployment 已经从 extensions/v1beta1 弃用

DaemonSet, Deployment, StatefulSet, and ReplicaSet resources will no longer be served from extensions/v1beta1, apps/v1beta1, or apps/v1beta2 by default in v1.16.



1,kubeadm init 后master一直处于notready状态------------flannel网络cni问题

https://blog.csdn.net/wangmiaoyan/article/details/101216496
kubeadm安装Kubernetes,集群状态检测时,master一直处于notready状态
[root@master ~]# kubectl get nodes
NAME     STATUS     ROLES    AGE    VERSION
master   NotReady   master   32m    v1.16.0
node1    NotReady      8m2s   v1.16.0
————————————————
[root@master ~]# kubectl get pods --all-namespaces
NAMESPACE     NAME                             READY   STATUS    RESTARTS   AGE
kube-system   coredns-58cc8c89f4-pkx82         0/1     Pending   0          34m
kube-system   coredns-58cc8c89f4-sddpq         0/1     Pending   0          34m
kube-system   etcd-master                      1/1     Running   0          34m
kube-system   kube-apiserver-master            1/1     Running   0          34m
kube-system   kube-controller-manager-master   1/1     Running   0          33m
kube-system   kube-proxy-4fj8z                 1/1     Running   0          10m
kube-system   kube-proxy-v54nh                 1/1     Running   0          34m
kube-system   kube-scheduler-master            1/1     Running   0          34m
————————————————
[root@master ~]# journalctl -f -u kubelet.service
-- Logs begin at Mon 2019-09-23 22:55:58 CST. --
Sep 24 01:33:44 master kubelet[6213]: E0924 01:33:44.107180    6213 kubelet.go:2187] Container runtime network not ready: NetworkReady=false reason:NetworkPluginNotReady message:docker: network plugin is not ready: cni config uninitialized
Sep 24 01:33:46 master kubelet[6213]: W0924 01:33:46.416805    6213 cni.go:237] Unable to update cni config: no networks found in /etc/cni/net.d
————————————————
先看镜flannel像有没有成功拉取docker images|grep flannel

重新flannel
[root@master ~]# kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/a70459be0084506e4ec919aa1c114638878db11b/Documentation/kube-flannel.yml
clusterrole.rbac.authorization.k8s.io/flannel unchanged
clusterrolebinding.rbac.authorization.k8s.io/flannel unchanged
serviceaccount/flannel unchanged
configmap/kube-flannel-cfg unchanged
unable to recognize "https://raw.githubusercontent.com/coreos/flannel/a70459be0084506e4ec919aa1c114638878db11b/Documentation/kube-flannel.yml": no matches for kind "DaemonSet" in version "extensions/v1beta1"
unable to recognize "https://raw.githubusercontent.com/coreos/flannel/a70459be0084506e4ec919aa1c114638878db11b/Documentation/kube-flannel.yml": no matches for kind "DaemonSet" in version "extensions/v1beta1"
unable to recognize "https://raw.githubusercontent.com/coreos/flannel/a70459be0084506e4ec919aa1c114638878db11b/Documentation/kube-flannel.yml": no matches for kind "DaemonSet" in version "extensions/v1beta1"
unable to recognize "https://raw.githubusercontent.com/coreos/flannel/a70459be0084506e4ec919aa1c114638878db11b/Documentation/kube-flannel.yml": no matches for kind "DaemonSet" in version "extensions/v1beta1"
————————————————
换个flannel链接
[root@master ~]# kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
podsecuritypolicy.policy/psp.flannel.unprivileged created
clusterrole.rbac.authorization.k8s.io/flannel configured
clusterrolebinding.rbac.authorization.k8s.io/flannel unchanged
serviceaccount/flannel unchanged
configmap/kube-flannel-cfg unchanged
daemonset.apps/kube-flannel-ds-amd64 created
daemonset.apps/kube-flannel-ds-arm64 created
daemonset.apps/kube-flannel-ds-arm created
daemonset.apps/kube-flannel-ds-ppc64le created
daemonset.apps/kube-flannel-ds-s390x created
————————————————
还是noready的话,继续看日志,下载镜像docker pull quay.io/coreos/flannel:v0.11.0-amd64或者创建文件vim /etc/cni/net.d/10-flannel.conflist
或者修改文件版本号信息------------------
2 ,

安装docker时报container-selinux >= 2.9错误

由于测试环境的机器是不同批准到来的,第一批安装非常顺序,第二批是直接放置在办公室的PC机,也非常不顺序,安装过程遇到各种各样麻烦.

上面说过,加入集群时发现docker没有安装成功,安装docker时出现了以下错误

Error: Package: docker-ce-18.03.1.ce-1.el7.centos.x86_64 (docker-ce-edge)
           Requires: container-selinux >= 2.9
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest

这个报错是container-selinux版本低或者是没安装的原因

yum 安装container-selinux 一般的yum源又找不到这个包

需要安装epel源 才能yum安装container-selinux

然后在安装docker-ce就可以了。

wget -O /etc/yum.repos.d/CentOS-Base.repo 

yum install epel-release #阿里云上的epel源

yum makecache

然后yum install container-selinux

3,

节点加入集群时报错

节点加入集群时,可能会报各种各样的错误,有些容易解决,有些可能一时无法找到好的解决办法.这时候可以尝试使用kubeadm reset命令来重置一下,然后再重新加入.
4,Kubernetes pods ContainerCreating处理方法


kubectl describe pod mysql,查看具体错误信息解决

重新加载
kubectl delete pod mysql-k82bf  先删pod
kubectl delete rc mysql删除rc
kubectl create -f mysql-rc.yaml重新创建
kubectl get pods
docker ps -a
5,在master进行Kubernetes集群初始化。注意版本号信息
kubeadm init --kubernetes-version=1.14.2 (kubelet --version
6,pod是pending的没有节点可用

此时发现一个警告:0/1 nodes are available: 1 node(s) had taints that the pod didn’t tolerate.

该问题是因为没有可用的节点NODE,所以无法部署

7,kubectl无法使用,swap的原因
[root@k8s-master ~]# kubectl get pods
The connection to the server 192.168.200.131:6443 was refused - did you specify the right host or port?
8,拉取flannel时可能遇到的问题
wget https://raw.githubusercontent.com/coreos/flannel/a70459be0084506e4ec919aa1c114638878db11b/Documentation/kube-flannel.yml //在kube-flannel.yml里面默认的镜像下载地址是quay.io,国内无法访问,这里替换所有的quay.io为 quay-mirror.qiniu.com sed -i "s/quay.io/quay-mirror.qiniu.com/g" kube-flannel.yml
执行安装命令
kubectl apply -f kube-flannel.yml
9,token 24小时过期问题,如何再新加节点
kubeadm token create
openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | 
openssl dgst -sha256 -hex | sed 's/^.* //'
kubeadm join --token aa78f6.8b4cafc8ed26c34f --discovery-token-ca-cert-hash sha256:0fd95a9bc67a7bf0ef42da968a0d55d92e52898ec37c971bd77ee501d845b538  172.16.6.79:6443 --skip-preflight-checks
[root@localhost /]#
[root@localhost /]# kubeadm token create
W0113 15:08:50.563495   12879 validation.go:28] Cannot validate kube-proxy config - no validator is available
W0113 15:08:50.563549   12879 validation.go:28] Cannot validate kubelet config - no validator is available
fsr5mw.tzxbi8w3nq96mnrq
[root@localhost /]# kubeadm token list
TOKEN                     TTL         EXPIRES                     USAGES                   DESCRIPTION                                                EXTRA GROUPS
fsr5mw.tzxbi8w3nq96mnrq   23h         2020-01-14T15:08:50+08:00   authentication,signing                                                        system:bootstrappers:kubeadm:default-node-token
jn34ao.wg31g5bi11cflq08   23h         2020-01-14T15:08:44+08:00   authentication,signing                                                        system:bootstrappers:kubeadm:default-node-token
ylaxra.w6wqqswi75ui2ztb   19h         2020-01-14T10:18:14+08:00   authentication,signing                                                        system:bootstrappers:kubeadm:default-node-token
[root@localhost /]#

阅读(29127) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~