# geekcloudnative **Repository Path**: ceagle/geek_cloud_native ## Basic Information - **Project Name**: geekcloudnative - **Description**: learn cloud native - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-03-16 - **Last Updated**: 2024-10-07 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 创建git ``` mkdir geek_cloud_native cd geek_cloud_native git init touch README.md git add README.md git commit -m "first commit" git remote add origin https://gitee.com/ceagle/geek_cloud_native.git git push -u origin "master" ``` # 编译二级制 ```bash CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/amd64 . ``` # 构建镜像 ```bash docker build -f Dockerfile -t go_httpserver . ``` # 删除已经启动的同名容器 ```bash docker rm -f go_httpserver ``` # 启动容器 ```bash docker run -d -ti --name go_httpserver --net=host go_httpserver docker run -d -ti --name go_httpserver 5a69f717e700 ``` # 登录容器 ```bash docker exec -ti go_httpserver bash ``` 验证web服务器 ```bash 启动web服务器 root@ubuntu:/# ./httpserver VERSION NO CONFIGED 127.0.0.1:8080|127.0.0.1:54406|200 访问web服务器 curl http://127.0.0.1:8080/healthz root@ubuntu:/# curl http://127.0.0.1:8080/healthz Hello,healthz request 中带的 header 写入 response header: User-Agent [curl/7.68.0] Accept [*/*] Version [NO CONFIGED] 返回码: 200 ``` # 打标签 ```bash docker tag d7c71cba5681 docker.io/ceagle/httpserver:v1.0 或者 docker tag d7c71cba5681 ceagle/httpserver:v1.0 ``` # 推送镜像到 hub.docker.com ```bash docker push docker.io/ceagle/httpserver:v1.0 或者 docker push ceagle/httpserver:v1.0 ``` # httpserver 镜像地址 ```bash https://hub.docker.com/r/ceagle/httpserver ``` # 制作 ubuntu go环境 ```bash docker run -d -ti --name ubuntu_init ubuntu docker exec -ti ubuntu_init bash ``` ubuntu 更换源,这里是阿里源 ```bash sudo tee /etc/apt/sources.list <<-'EOF' deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse EOF apt-get upgrade -y && apt-get update ``` ```bash apt-get install net-tools apt-get install wget -y wget -c -q -O - https://dl.google.com/go/go1.20.2.linux-amd64.tar.gz | tar -zxvf - -C /usr/local/ export PATH=$PATH:/usr/local/go/bin tee $HOME/.profile <<-'EOF' # ~/.profile: executed by Bourne-compatible login shells. if [ "$BASH" ]; then if [ -f ~/.bashrc ]; then . ~/.bashrc fi fi mesg n 2> /dev/null || true EOF echo 'export PATH=$PATH:/usr/local/go/bin' >> $HOME/.profile source $HOME/.profile ``` 保存ubuntu镜像 ```sh docker commit 08a2c8bf266f ceagle/ubuntu20.04.3-go1.20.2:v1.0 ``` ---------------------------------------------------------------- make 安装 ```bash sudo apt-get install make ``` # 作业 ## 构建本地镜像 https://registry.hub.docker.com/_/registry/ ```bash # 拉取镜像 docker pull registry # 本地搭建 映射端口,容器内默认为:5000 docker run -d -p 5000:5000 registry ``` 本地镜像上传到私有registry ```bash # 打tag docker tag nginx:alpine 127.0.0.1:5000/nginx:alpine # push 到私有仓库 docker push 127.0.0.1:5000/nginx:alpine # 删除本地镜像 docker rmi 127.0.0.1:5000/nginx:alpine # 从本地仓库拉取镜像 docker pull 127.0.0.1:5000/nginx:alpine ``` ## 编写 Dockerfile 将模块二作业编写的 httpserver 容器化 见Dockerfile ## 将镜像推送至 docker 官方镜像仓库 见Makefile `make release` ## 通过 docker 命令本地启动 httpserver `docker run -d --name=local_httpserver --net=host go_httpserver` ## 通过 nsenter 进入容器查看 IP 配置 ```bash ceagle@ubuntu:~$ docker inspect local_httpserver|grep -i pid "Pid": 4217, "PidMode": "", "PidsLimit": null, ceagle@ubuntu:~$ nsenter -t 4217 -n ip a 1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever ... ``` # CRD:扩展