0. Preconditions

  • K8s cluster (Kubeadm deploys one master and two slave K8S clusters)
  • Installing helm (refer to official documentation)
  • Docker enable remote access mode, method:
Sudo vim/usr/lib/systemd/system/docker. Service to modify this line, behind plus - H TCP: / / 0.0.0.0:2375: ExecStart = / usr/bin/dockerd -h fd: / / -- containerd = / run/containerd containerd. The sock - H TCP: / / 0.0.0.0:2375 sudo systemctl daemon-reload sudo systemctl restart dockerCopy the code

1. Write the Golang app

Front end: github.com/chintensaka… The backend: github.com/chintensaka…

Vue + Golang docker API visualization small project,

Current progress: 35%, front-end UI framework completed, container list interface completed; The introduction of back-end GIN framework and Docker Go SDK was completed, the front and back end call interfaces of container list were completed, and the front and back end of container was started and stopped

Run first. Don’t try to be perfect at first.

“We know it’s not perfect and it’s problematic, but it gets things off the ground, and it’s important not to linger on trying to get things perfect the first time.”

2. Dockerfile

Alpine AS build-env WORKDIR /opt/apps/docker-visualizing COPY. /opt/apps/docker-visualizing env GOOS linux ENV GOARCH amd64 ENV GOPROXY https://goproxy.cn,direct RUN go build -v -o /opt/apps/docker-visualizing/app FROM alpine COPY --from=build-env /opt/apps/docker-visualizing/app /usr/local/bin/app COPY --from=build-env /opt/apps/docker-visualizing/conf/app.ini /usr/local/bin/ RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime EXPOSE 9281 CMD ["app"]Copy the code
Docker run -d --name = docker run --name = docker run --name = docker run --name = docker run --name = docker run --name = docker run --name = docker run --name docker-visualizing -p 9281:9281 chins/docker-visualizingCopy the code

As of now, deploying golang(GIN) applications with Docker is complete: Gin applications within docker containers can be accessed externally:

Docker build:

Docker run:

Access:

3. Deploy applications using the helm

3.1 Creating the Helm Application Template

helm create docker-visualizing
Copy the code

3.2 Edit deploy, Service, and ingress (if ingress is used) separately

I’m only using NodePort to expose the service here, I’ll come back to optimize when I learn ingress, and the live probe and ready probe are not needed now, comment it out. Yaml = value.yaml = value.yaml = value.yaml

Yaml: spec: type: {{.values.service. type}} # values.yaml: NodePort service: type: NodePort port Change the name of your build image to image: repository: chins/docker-visualizingCopy the code

3.3 package && install

# 1. Pack chart package Helm Package Docker-VisualizingCopy the code

I have two nodes, the image is compiled on the master, and I have not uploaded the image to the repository, so I need to copy the image on the master to both nodes. Otherwise, when installing, the image will not be pulled from the repository because there is no local image on the node:

## master node  sudo docker save chins/docker-visualizing:latest -o docker-visualizing.tar scp docker-visualizing.tar [email protected]: / home/ubuntu SCP docker - visualizing. Tar [email protected]: / home/ubuntu # # node node:  sudo docker load -i docker-visualizing.tarCopy the code

# 2. Helm Install Docker-visualizing./ Docker-visualizing -0.1.0.tgzCopy the code

1. Get the application URL by running these commands: export NODE_PORT=$(kubectl get --namespace default -o jsonpath="{.spec.ports[0].nodePort}" services docker-visualizing) export NODE_IP=$(kubectl get nodes --namespace default -o jsonpath="{.items[0].status.addresses[0].address}") echo http://$NODE_IP:$NODE_PORTCopy the code

4. Visit: http://192.168.1.248:30484/pingCopy the code

4. The end.

Getting the application up and running is just the first step, there is still a lot of work to do, such as various YAML writing, health check, ingress, etc., as well as the application code optimization, there are many variables can be extracted into the environment variables, secret/ Configmap, etc., try again at some time.