本实验来自k8s权威指南
解决访问demo出错,关键是靠https://www.cnblogs.com/neutronman/p/8047547.html此链接下面的某个大神的评论
主要yaml文件
1:myweb-rc.raml 注意书上结尾有环境变量,加上环境变量的时候无法访问demo,访问demo出错,无法和数据库连接。如果还不行那就删掉mysqlpod重新改一下rc的值,另外我把mysql的版本换成5.5了不知道和这个是否也有关系
[root@centos-master k8s]# cat myweb-rc.yaml kind: ReplicationController metadata: name: myweb spec: replicas: 6 selector: app: myweb template: metadata: labels: app: myweb spec: containers: - name: myweb image: kubeguide/tomcat-app:v1 ports: - containerPort: 8080
[root@centos-master k8s]# cat myweb-svc.yaml apiVersion: v1 kind: Service metadata: name: myweb spec: type: NodePort ports: - port: 8080 nodePort: 30001 selector: app: myweb
[root@centos-master k8s]# cat 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:5.5 ports: - containerPort: 3306 env: - name: MYSQL_ROOT_PASSWORD value: "123456"
[root@centos-master k8s]# cat mysql-svc.yaml apiVersion: v1 kind: Service metadata: name: mysql spec: ports: - port: 3306 selector: app: mysql
3:生成相应的docker镜像
kubectl create -f 上面的yaml文件
最后访问成功