k8s踩坑记第1篇--rc无法创建

六一快乐!!!

什么是k8s,我不想解释,百度资料有很多,本系列只踩坑,不科普。

问题描述:

做Hello World的例子,结果get pods一直显示没有资源?

应用配置代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
apiVersion : v1
kind : ReplicationController
metadata :
name : mysql
spec :
replicas : 2
selector :
app : mysql
template :
metadata :
labels :
app : mysql
spec :
containers :
- name : mysql
image : mysql
ports :
- containerPort : 3306
env :
- name : MYSQL_ROOT_PASSWORD
value : "123456"

创建rc

1
2
3
4
5
6
7
8
9
10
# kubectl create -f mysql-rc.yaml 
replicationcontroller "mysql" created
# kubectl get rc
NAME DESIRED CURRENT READY AGE
mysql 2 0 0 11s
myweb 2 0 0 5s
# kubectl get pods
No resources found.
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE

分析

创建了rc之后,虽然命令行提示成功了,但是pods一直没有创建,也检查了docker,mysql的镜像没有拉取。又仔细看了一边rc的结果,current和ready列的值是0,应该先解决current为0的问题。

google解决方案

  1. executed command :

    openssl genrsa -out /tmp/serviceaccount.ket 2048

  2. modified the /etc/kubernetes/apiserver file to add following :

    KUBE_API_ARGS=”–service_account_key_file=/tmp/serviceaccount.key”

  3. modified the /etc/kubernetes/controller-manager and add following: 

    KUBE_CONTROLLER_MANAGER_ARGS=”–service_account_private_key_file=/tmp/serviceaccount.key”

  4. restarted the kube-apiserver and kube-controller-manager services to restart the services
    1
    2
    service kube-apiserver restart
    service kube-controller-manager restart

参考:
https://blog.csdn.net/jinzhencs/article/details/51435020
https://github.com/kubernetes/kubernetes/issues/11355#issuecomment-127378691