本文的环境介绍
[root@m-30-1 ~]# kubectl version
Client Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.2", GitCommit:"81753b10df112992bf51bbc2c2f85208aad78335", GitTreeState:"clean", BuildDate:"2018-04-27T09:22:21Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.2", GitCommit:"81753b10df112992bf51bbc2c2f85208aad78335", GitTreeState:"clean", BuildDate:"2018-04-27T09:10:24Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}
[root@m-30-1 ~]# rpm -qf /etc/issue
centos-release-7-4.1708.el7.centos.x86_64
kubernetes集群是通过kubeadm安装的
首先创建镜像
[root@m-30-2 nginx-wis]# pwd
/opt/dockerfile/nginx-wis
[root@m-30-2 nginx-wis]# ls
Dockerfile index.html
[root@m-30-2 nginx-wis]# cat Dockerfile
FROM nginx
MAINTAINER wis
COPY index.html /usr/share/nginx/html/index.html
[root@m-30-2 nginx-wis]# cat index.html
hello from wis
然后创建镜像,我们可以先打一个简单的tag然后在打一个私仓的tag,不过我们的这个镜像最终也是要传到私仓,所以直接打私仓的tag
[root@m-30-2 nginx-wis]# docker build . -t harbor.my.domain/library/wis-nginx
Sending build context to Docker daemon 3.072 kB
Step 1/3 : FROM nginx
---> ae513a47849c
Step 2/3 : MAINTAINER wis
---> Running in 29aeb5fdae33
---> b68a66ae794c
Removing intermediate container 29aeb5fdae33
Step 3/3 : COPY index.html /usr/share/nginx/html/index.html
---> 81945be11b0c
Removing intermediate container be67728dad51
Successfully built 81945be11b0c
登录私仓 默认的用户名密码admin/Harbor12345,docker的systemd启动文件中要加入--insecure-registry harbor.my.domain
,然后我是本机绑的hosts,我用的harbor私仓在172.16.30.1 harbor.my.domain
,这个机器上
docker login harbor.my.domain
登录成功后
[root@m-30-2 nginx-wis]# docker push harbor.my.domain/library/wis-nginx
The push refers to a repository [harbor.my.domain/library/wis-nginx]
6a1acaa1b8e7: Pushed
7ab428981537: Pushed
82b81d779f83: Pushed
d626a8ad97a1: Pushed
latest: digest: sha256:974de0760e53a8d46c07ce7ff985e0aca55380e9ae134bbf82fcc1ac8b98324c size: 1155
[root@m-30-2 nginx-wis]#
创建wis-nginx的deployment和service
[root@m-30-2 ingress]# kubectl run wis-nginx --image=harbor.my.domain/library/wis-nginx --expose=true --port=80
service "wis-nginx" created
deployment.apps "wis-nginx" created
创建ingress
[root@m-30-2 ingress]# pwd
/opt/ingress
[root@m-30-2 ingress]# cat wis-nginx.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: wis-nginx
namespace: ops
spec:
rules:
- host: wis-nginx.com
http:
paths:
- backend:
serviceName: wis-nginx
servicePort: 80
本机绑定这个hosts
172.16.30.2 wis-nginx.com
然后本机就能访问这个页面了(在浏览器输入 wis-nginx.com
)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)