This is a demo project required by SRE role.
The candidate should be able to complete the project independently in two days and well document the procedure in a practical and well understanding way.
It is not guaranteed that all tasks can be achieved as expected, in which circumstance, the candidate should trouble shoot the issue, conclude based on findings and document which/why/how.
Task 0: Install a ubuntu 18.04 server 64-bit
either in a physical machine or a virtual machine (choose any hypervisor like virtualbox, vmware workstation/fusion, kvm, hyper-v, …. )
Use virtualbox as a quick start: https://www.virtualbox.org/
http://releases.ubuntu.com/18.04/
http://releases.ubuntu.com/18.04/ubuntu-18.04.5-live-server-amd64.iso
https://segmentfault.com/a/1190000022468063
For virtualbox VM, use network NAT and forward required ports to host machine, like:
22->22222 for ssh
80->28080 for gitlab
8081/8082->28081/28082 for go app
31080/31081->31080/31081 for go app in k8s
Task 1: Update system
ssh to guest machine from host machine ($ ssh user@localhost -p 22222) and update the system to the latest
https://help.ubuntu.com/18.04/serverguide/apt.html
upgrade the kernel to the 18.04 latest
Note: You may need to change the default apt repo to local to avoid network issue, like:
# cat /etc/apt/sources.list
deb http://mirrors.163.com/ubuntu bionic main restricted
deb http://mirrors.163.com/ubuntu bionic-updates main restricted
deb http://mirrors.163.com/ubuntu bionic universe
deb http://mirrors.163.com/ubuntu bionic-updates universe
deb http://mirrors.163.com/ubuntu bionic multiverse
deb http://mirrors.163.com/ubuntu bionic-updates multiverse
deb http://mirrors.163.com/ubuntu bionic-backports main restricted universe multiverse
deb http://mirrors.163.com/ubuntu bionic-security main restricted
deb http://mirrors.163.com/ubuntu bionic-security universe
deb http://mirrors.163.com/ubuntu bionic-security multiverse
1 | mv /etc/apt/sources.list /etc/apt/sources.list.bak |
Task 2: install gitlab-ce version in the host
https://about.gitlab.com/install/#ubuntu?version=ce
Expect output: Gitlab is up and running at http://127.0.0.1 (no tls or FQDN required)
Access it from host machine http://127.0.0.1:28080
参考:https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-gitlab-on-ubuntu-18-04
1 | sudo apt update |
Task 3: create a demo group/project in gitlab
named demo/go-web-hello-world (demo is group name, go-web-hello-world is project name).
Use golang to build a hello world web app (listen to 8081 port)
Check-in the code to mainline (need to use git).
https://golang.org/
https://gowebexamples.com/hello-world/
Expect source code at http://127.0.0.1:28080/demo/go-web-hello-world
Task 4: build the app and expose ($ go run) the service to 28081 port
Expect output from host machine:
curl http://127.0.0.1:28081
Go Web Hello World!
Task 5: install docker
https://docs.docker.com/install/linux/docker-ce/ubuntu/
Note: To avoid default docker repo access issue (could not pull images), you can add mirror registry like this:
# cat /etc/docker/daemon.json
{
“registry-mirrors”: [“https://hub-mirror.c.163.com"]
}
# systemctl daemon-reload
# systemctl restart docker
1 | apt install ca-certificates curl gnupg lsb-release |
Task 6: run the app in container
build a docker image ($ docker build) for the web app and run that in a container ($ docker run), expose the service to 28082 (-p)
https://docs.docker.com/engine/reference/commandline/build/
Check in the Dockerfile into gitlab
Expect output from host machine:
curl http://127.0.0.1:28082
Go Web Hello World!
1 | package main |
Error response from daemon: Get https://registry-1.docker.io/v2/: dial tcp: lookup registry-1.docker.io: Temporary failure in name resolution
Q:删除所有none镜像
docker rmi docker images | grep "<none>" | awk '{print $3}'
参考: https://blog.csdn.net/weixin_42581414/article/details/105954828
Task 7: push image to dockerhub
tag the docker image using your_dockerhub_id/go-web-hello-world:v0.1 and push it to docker hub (https://hub.docker.com/)
Expect output: https://hub.docker.com/repository/docker/your_dockerhub_id/go-web-hello-world
Task 8: document the procedure in a MarkDown file
create a README.md file in the gitlab repo and add the technical procedure above (0-7) in this file
Task 9: install a single node Kubernetes cluster using kubeadm
https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/
Check in the admin.conf file into the gitlab repo
1 | sudo apt-get update |
https://blog.csdn.net/qq_44895681/article/details/107413950
https://blog.csdn.net/H12590400327/article/details/103740602
https://www.jianshu.com/p/8e78e0abddf9
https://blog.csdn.net/weixin_43168190/article/details/107227626
https://www.cnblogs.com/dream397/p/13814166.html
https://www.quwenqing.com/archives/1899.html
1 | kubeadm init --image-repository=registry.aliyuncs.com/google_containers |
Task 10: deploy the hello world container
in the kubernetes above and expose the service to nodePort 31080
Expect output:
curl http://127.0.0.1:31080
Go Web Hello World!
Check in the deployment yaml file or the command line into the gitlab repo
https://kubernetes.io/zh-cn/docs/reference/kubectl/cheatsheet/
https://kubernetes.io/zh-cn/docs/tasks/debug/debug-application/_print/
1 | kubectl get nodes # 节点,相当于一台容器 |
1 | apiVersion: v1 |
Task 11: install kubernetes dashboard
and expose the service to nodeport 31081
https://kubernetes.io/docs/tasks/access-application-cluster/web-ui-dashboard/
Expect output: https://127.0.0.1:31081 (asking for token)
Task 12: generate token for dashboard login in task 11
figure out how to generate token to login to the dashboard and publish the procedure to the gitlab.
1 | https://github.com/kubernetes/dashboard/blob/master/docs/user/access-control/creating-sample-user.md |
Task 13: publish your work
push all files/procedures in your local gitlab repo to remote github repo (e.g. https://github.com/your_github_id/go-web-hello-world)
if this is for an interview session, please send it to bo.cui@ericsson.com, no later than two calendar days after the interview.
1 | apiVersion: apps/v1 |
1 | apiVersion: v1 |
报错
1 | 单节点,preemption: 0/1 nodes are available: 1 Preemption is not helpful for scheduling |