linux k8s权威踩坑指南

葫芦的运维日志

下一篇 搜索 上一篇

浏览量 5007

2019/05/19 21:17


k8s权威采坑指南

初学k8s照着书敲的代码,还是采坑不断。

第一坑:  pod服务一直处于 ContainerCreating

open /etc/docker/certs.d/registry.access.redhat.com/redhat-ca.crt: no such file or directory

wget http://mirror.centos.org/centos/7/os/x86_64/Packages/python-rhsm-certificates-1.19.10-1.el7_4.x86_64.rpm
rpm2cpio python-rhsm-certificates-1.19.10-1.el7_4.x86_64.rpm | cpio -iv --to-stdout ./etc/rhsm/ca/redhat-uep.pem | tee /etc/rhsm/ca/redhat-uep.pem

前两个命令会生成/etc/rhsm/ca/redhat-uep.pem文件

docker pull registry.access.redhat.com/rhel7/pod-infrastructure:latest

第二坑: 看不到demo页面,报错连接数据库失败

Error:com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.

 

书中代码:mysql-rc.yaml

apiVersion: v1
kind: ReplicationController
metadata:
  name: mysql
spec:
  replicas: 1
  selector:
    app: mysql
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
      - name: mysql
        image: mysql
        ports:
        - containerPort: 3306
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: "123456"

(网上有人说需要进入docker 修改hosts自测没用)

docker ps 查出 实例id后通过下面命令进入docker实例

docker exec -ti  aff0fec8f07b  /bin/bash

 

解决:无法连接数据库,书籍中mysql是latest,但是当时是15-16年左右,原来jdbc驱动可用,但是现在yaml文件中没有版本号,默认依然是latest,但是现在的jdbc驱动不能连接latest版本的mysql,故进行滚动升级命令如下:

 

[root@k8s-master k8s]#kubectl rolling-update mysql --image=mysql:5.7

踩了俩坑之后 终于见到了 demo页面,如下:

 

常用重启命令

systemctl restart etcd
systemctl restart docker
systemctl restart kube-apiserver
systemctl restart kube-controller-manager
systemctl restart kube-scheduler
systemctl restart kubelet
systemctl restart kube-proxy

常用查看命令

[root@k8s-master k8s]# docker inspect --format='{{.Name}} - {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(docker ps -aq)
/k8s_mysql.ab2b1c27_mysql-b50678a13c0ae29a464ccca90f0dfce3-bvtj9_default_a106263f-7a37-11e9-bad0-5254004a32f3_c839aadd -
/k8s_POD.1d520ba5_mysql-b50678a13c0ae29a464ccca90f0dfce3-bvtj9_default_a106263f-7a37-11e9-bad0-5254004a32f3_c684a0ac - 172.17.0.5
/k8s_myweb.38f06b7_myweb-r0cjx_default_5cffdc6c-7a12-11e9-875d-5254004a32f3_5cd7f99a -
/k8s_myweb.38f06b7_myweb-9qnss_default_5cff99af-7a12-11e9-875d-5254004a32f3_98c9b9f8 -
/k8s_POD.24f70ba9_myweb-9qnss_default_5cff99af-7a12-11e9-875d-5254004a32f3_edca5273 - 172.17.0.3
/k8s_POD.24f70ba9_myweb-r0cjx_default_5cffdc6c-7a12-11e9-875d-5254004a32f3_0624f3ff - 172.17.0.2
/k8s_myweb.38f06b7_myweb-9qnss_default_5cff99af-7a12-11e9-875d-5254004a32f3_7b25125f -
/k8s_myweb.38f06b7_myweb-r0cjx_default_5cffdc6c-7a12-11e9-875d-5254004a32f3_d5085529 -
/k8s_POD.24f70ba9_myweb-r0cjx_default_5cffdc6c-7a12-11e9-875d-5254004a32f3_3df5d109 -
/k8s_POD.24f70ba9_myweb-9qnss_default_5cff99af-7a12-11e9-875d-5254004a32f3_ee595381 -

[root@k8s-master k8s]# docker ps
CONTAINER ID        IMAGE                                                        COMMAND                  CREATED             STATUS              PORTS               NAMES
9dabea691d86        mysql:5.7                                                    "docker-entrypoint..."   31 minutes ago      Up 31 minutes                           k8s_mysql.ab2b1c27_mysql-b50678a13c0ae29a464ccca90f0dfce3-bvtj9_default_a106263f-7a37-11e9-bad0-5254004a32f3_c839aadd
6a70b3f7eb2a        registry.access.redhat.com/rhel7/pod-infrastructure:latest   "/usr/bin/pod"           32 minutes ago      Up 32 minutes                           k8s_POD.1d520ba5_mysql-b50678a13c0ae29a464ccca90f0dfce3-bvtj9_default_a106263f-7a37-11e9-bad0-5254004a32f3_c684a0ac
aff0fec8f07b        kubeguide/tomcat-app:v1                                      "catalina.sh run"        47 minutes ago      Up 47 minutes                           k8s_myweb.38f06b7_myweb-r0cjx_default_5cffdc6c-7a12-11e9-875d-5254004a32f3_5cd7f99a
bb8ee8e6df5b        kubeguide/tomcat-app:v1                                      "catalina.sh run"        47 minutes ago      Up 47 minutes                           k8s_myweb.38f06b7_myweb-9qnss_default_5cff99af-7a12-11e9-875d-5254004a32f3_98c9b9f8
a71789435e34        registry.access.redhat.com/rhel7/pod-infrastructure:latest   "/usr/bin/pod"           47 minutes ago      Up 47 minutes                           k8s_POD.24f70ba9_myweb-9qnss_default_5cff99af-7a12-11e9-875d-5254004a32f3_edca5273
3ff82f627a84        registry.access.redhat.com/rhel7/pod-infrastructure:latest   "/usr/bin/pod"           47 minutes ago      Up 47 minutes                           k8s_POD.24f70ba9_myweb-r0cjx_default_5cffdc6c-7a12-11e9-875d-5254004a32f3_0624f3ff
[root@k8s-master k8s]# kubectl get rc
NAME      DESIRED   CURRENT   READY     AGE
mysql     1         1         1         30m
myweb     2         2         2         4h
[root@k8s-master k8s]# kubectl get pods
NAME                                           READY     STATUS    RESTARTS   AGE
mysql-b50678a13c0ae29a464ccca90f0dfce3-bvtj9   1/1       Running   0          31m
myweb-9qnss                                    1/1       Running   5          4h
myweb-r0cjx                                    1/1       Running   5          4h
[root@k8s-master k8s]# kubectl get services
NAME         CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
kubernetes   10.254.0.1      <none>        443/TCP          10h
mysql        10.254.163.9    <none>        3306/TCP         5h
myweb        10.254.135.39   <nodes>       8080:30001/TCP   4h
[root@k8s-master k8s]#

 

葫芦的运维日志

打赏

上一篇 搜索 下一篇
© 冰糖葫芦甜(bthlt.com) 2021 王梓打赏联系方式 陕ICP备17005322号-1