1: 今天开始k8s 的的实践啦:

示例:实现 运行在 Tomcat里的 Web app,JSP页面通过 JDBC 直接访问 MySQL数据库并展示数据。

需求:Web App 容器 MySQL容器,web--->mysql

         需要把MySQL容器的IP地址通过环境变量的方式注入 Web App容器里,同时,需要将Web App容器的 8080端口映射宿主机的 8080端口,以便在外部访问。

1: 先编写第一个yaml 文件;

1.YAML编写

1.MySQL服务创建一个 RC 文件

# cat mysql-rc.yaml
apiVersion: apps/v1beta1    (把这行改成:apiVersion: extensions/v1beta1  就不报错啦 )
kind: Deployment
metadata:
  name: mysql
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mysql
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
      - name: mysql
        image: mysql:5.7
        ports:
        - containerPort: 3306
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: "123456"

创建好以后:

[root@k8s-master script]# kubectl get pods
NAME                     READY     STATUS              RESTARTS   AGE
mysql-4144028371-3v7nb   0/1       ContainerCreating   0          28s

然后trouble shooting :

kubectl describe pod

发现如下的报错:

    Error syncing pod, skipping: failed to "StartContainer" for "POD" with ErrImagePull: "image pull failed for registry.access.redhat.com/rhel7/pod-infrastructure:latest, this may be because there are no credentials on this request.  details: (open /etc/docker/certs.d/registry.access.redhat.com/redhat-ca.crt: no such file or directory)"

image 没有pull:

下面一步步解决:

systemctl daemon-reload
service docker restart
service docker status (should see active (running))

[root@k8s-master script]# docker pull registry.access.redhat.com/rhel7/pod-infrastructure:latest
Trying to pull repository registry.access.redhat.com/rhel7/pod-infrastructure ...
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
成功了:

[root@k8s-master ca]# docker pull registry.access.redhat.com/rhel7/pod-infrastructure:latest
Trying to pull repository registry.access.redhat.com/rhel7/pod-infrastructure ...
latest: Pulling from registry.access.redhat.com/rhel7/pod-infrastructure
26e5ed6899db: Pull complete
66dbe984a319: Pull complete
9138e7863e08: Pull complete
Digest: sha256:92d43c37297da3ab187fc2b9e9ebfb243c1110d446c783ae1b989088495db931
Status: Downloaded newer image for registry.access.redhat.com/rhel7/pod-infrastructure:latest

 

-----

注意: 上面的操作在node 上都要再做一遍。

2: 下面把rc 删除了重新建:

kubectl delete -f mysql-rc.yaml

kubectl create -f mysql-rc.yaml

3: 重起一下server, 或者 master,node 上的服务,就好了:

[root@k8s-master script]# kubectl get pod
NAME                     READY     STATUS    RESTARTS   AGE
mysql-4144028371-l6d0m   1/1       Running   0          41m

Logo

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

更多推荐