0. Introduction
This time to look at entry-CI / CD, and before too simple to understand Jenkins, now trying to figure below this architecture to build up. May be one or two foreign command to install things done, I toss two more days, really almost gave up.
1. Install VirtualBox
refer to this official document https://www.virtualbox.org/wiki/Linux_Downloads
add the following in /etc/apt/sources.list
deb [arch=amd64] https://download.virtualbox.org/virtualbox/debian stretch contrib
Download signature
1 wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add - 2 apt-get update 3 apt-get install virtualbox-6.0
After installation, it is best to restart it.
2. Install the operating system
to download debian mirror
wget https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-10.1.0-amd64-netinst.iso
Create a mirror, and then configure it to start the iso image, then install the operating system.
Then there is the normal Linux installed
after a successful installation, the installation of several everyday tools, you can copy multiple image out, then you can practice.
Modify VM virtual machine is a bridge, it can be run from any computer within the local area network access via IP.
PermitRootLogin yes modify / etc / ssh / sshd_confg allow the root user login.
3. Installation Docker
Debian10 can be installed directly, without modifying /etc/apt/source.list
apt-get install docker.io
Creating /etc/docker/daemon.json file and add the following:
1 { 2 "registry-mirrors": ["https://xd80iytl.mirror.aliyuncs.com"] 3 }
If there are other image library, there may be added to the value of registry-mirrors is an array;
Restart Service docker
service docker restart
4. Installation kubernetes
4.1 Installation k8s
increases certificate
wget -q https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg -O- | apt-key add -
To increase /etc/apt/source.list
1 deb https: // mirrors.aliyun.com/kubernetes/apt/ kubernetes xenial maint- 2 apt get update 3 apt -y installation kubeadm kubectl kubectx kubelet kubernetes-cm
4.2 modify the three host name, and wrote / etc / hosts
1 hostnamectl set-hostname master 2 hostnamectl set-hostname node1 3 hostnamectl set hostname node2
Write to / etc / hosts
1 172.16.23.200 master 2 172.16.23.142 node1 3 172.16.23.157 node2
4.3 modify kernel parameters
to modify kernel parameters /etc/sysctl.d/k8s.conf
1 net.bridge.bridge-nf-call-ip6tables = 1 2 net.bridge.bridge-nf-call-iptables = 1 3 net.ipv4.ip_forward = 1
Effective immediately
sysctl --system
如果还报这个错
[ERROR FileContent--proc-sys-net-bridge-bridge-nf-call-iptables]: /proc/sys/net/bridge/bridge-nf-call-iptables does not exist
[ERROR FileContent--proc-sys-net-ipv4-ip_forward]: /proc/sys/net/ipv4/ip_forward contents are not set to 1
#那么执行
modprobe br_netfilter
echo 1 > /proc/sys/net/bridge/bridge-nf-call-iptables
Close interaction memory swap 4.4
swapoff -a
4.5 Reset kubeadm
1 kubeadm reset 2 rm -rf ~ / .in / 3 service charge restart 4 systemctl status omelet
4.6 following the implementation of the Master Host
kubeadm init --apiserver-advertise-address=172.16.23.200 --pod-network-cidr 10.244.0.0/16 --image-repository registry.aliyuncs.com/google_containers --v=5
注意172.16.23.200 这个是Master主机IP。而10.244.0.0/16先要这么写,后续安装CNI的flannel插件的时候,会依赖这个虚拟网络地址。然后由于众所周知原因,需要指定镜像仓库为aliyuncs。
如果init过程中出现,错误,需要重置的,可以执行
1 kubeadm reset 2 rm -rf ~/.kube/
成功后截图【放心,一般没有那么容易成功,这个安装太多坑了】
4.7 按要求执行这些命令
1 mkdir -p $HOME/.kube 2 sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config 3 sudo chown $(id -u):$(id -g) $HOME/.kube/config
4.8 记录节点node加入集群的 kubeadm join 信息
1 kubeadm join 172.16.23.200:6443 --token rm9y0a.u550ra92k4rh9wca \ 2 --discovery-token-ca-cert-hash sha256:428c8c94afd1697cb8ca2d5c5571d194a0db4b91056219e7a9e9f31b9bf60037 3 4 #若忘记join token,可通过以下命令获取 5 kubeadm token create --print-join-command
4.9 安装CNI插件
执行 kubectl get nodes 发现status状态是 NotReady,通过service kubelet status 发现错误原因
1 root@master:~# kubectl get nodes 2 NAME STATUS ROLES AGE VERSION 3 master NotReady master 2m56s v1.16.2 4 root@master:~# service kubelet status 5 ● kubelet.service - kubelet: The Kubernetes Node Agent 6 Loaded: loaded (/lib/systemd/system/kubelet.service; enabled; vendor preset: enabled) 7 Drop-In: /etc/systemd/system/kubelet.service.d 8 └─10-kubeadm.conf 9 Active: active (running) since Wed 2019-11-06 10:04:54 CST; 3min 33s ago 10 Docs: https://kubernetes.io/docs/home/ 11 Main PID: 4498 (kubelet) 12 Tasks: 19 (limit: 2359) 13 Memory: 43.2M 14 CGroup: /system.slice/kubelet.service 15 └─4498 /usr/bin/kubelet --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf --config=/var/lib/kubelet/config.yaml --cgroup-driver=cgroupfs 16 17 Nov 06 10:08:04 master kubelet[4498]: W1106 10:08:04.523652 4498 cni.go:237] Unable to update cni config: no networks found in /etc/cni/net.d 18 Nov 06 10:08:04 master kubelet[4498]: E1106 10:08:04.852874 4498 kubelet.go:2187] Container runtime network not ready: NetworkReady=false reason:NetworkPluginNotReady message:docker: network plugin i 19 Nov 06 10:08:09 master kubelet[4498]: W1106 10:08:09.525813 4498 cni.go:237] Unable to update cni config: no networks found in /etc/cni/net.d 20 Nov 06 10:08:09 master kubelet[4498]: E1106 10:08:09.863154 4498 kubelet.go:2187] Container runtime network not ready: NetworkReady=false reason:NetworkPluginNotReady message:docker: network plugin i 21 Nov 06 10:08:14 master kubelet[4498]: W1106 10:08:14.527639 4498 cni.go:237] Unable to update cni config: no networks found in /etc/cni/net.d
出现Unable to connect to the server: x509: certificate signed by unknown authority (possibly because of “crypto/rsa: verification error” while trying to verify candidate authority certificate “kubernetes”) 修改配置
export KUBECONFIG=/etc/kubernetes/admin.conf
修改/etc/hosts 【我这里临时性访问不了这个网站,可以通过修改hosts,附件提供】
151.101.56.133 raw.githubusercontent.com
安装CNI
在安装完 Master 节点后,查看节点信息( kubectl get nodes)会发现节点的状态为noready。查看noready的原因发现是由于cni插件没有配置(容器网络接口)。其实这是由于还没有配置网络。可以配置多种网络,这里我们选用最长远的 fannel 网络进行配置。
1 wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml 2 kubectl apply -f kube-flannel.yml
如果要重置可以执行 kubectl delete -f kube-flannel.yml
由于kube-flannel.yml 里面镜像是来自quay.io, 需要改为 quay-mirror.qiniu.com
还是会出现 Unable to update cni config: No networks found in /etc/cni/net.d
解决:修改文件内容: /etc/systemd/system/kubelet.service.d/10-kubeadm.conf 第5行增加这句
Environment="KUBELET_NETWORK_ARGS=--network-plugin=cni --cni-conf-dir=/etc/cni/ --cni-bin-dir=/opt/cni/bin"
4.10 执行重新启动命令
1 systemctl daemon-reload 2 systemctl restart kubelet.service 3 service docker restart 4 service kubelet restart 5 # 等系统启动和服务发现,预计1-2分钟 6 kubectl get nodes
4.11 以上过程,如果出现不成功,重启再执行一遍,慢慢排查原因。
哈哈
5. 节点Node 加入 Master
在两个节点node1 和 node2 执行
1 kubeadm join 172.16.23.200:6443 --token rm9y0a.u550ra92k4rh9wca \ 2 --discovery-token-ca-cert-hash sha256:428c8c94afd1697cb8ca2d5c5571d194a0db4b91056219e7a9e9f31b9bf60037
在Master机上,执行查看命令
6. 练习启动Pod
1 #启动两个Nginx 2 kubectl run nginx --image=nginx:1.10 --port=80 --replicas=2 3 #通过 kubectl get pod --all-namespaces -o wide 发现一直处于ContainerCreating ,因为下载nginx 需要182M。等2-3分钟后,完成部署,处于Running状态 4 #排查问题 5 kubectl get pods 6 kubectl describe pod nginx 7 #删除 8 kubectl delete pod nginx-b864db7b7-lpc76 9 kubectl delete deployment nginx
通过YAML模版方式部署集群
1 apiVersion: apps/v1 2 kind: Deployment 3 metadata: 4 name: nginx1 5 spec: 6 replicas: 1 7 selector: 8 matchLabels: 9 name: nginx1 10 template: 11 metadata: 12 labels: 13 name: nginx1 14 spec: 15 containers: 16 - name: nginx1 17 image: nginx:1.13 18 imagePullPolicy: IfNotPresent 19 ports: 20 - containerPort: 80 21 --- 22 apiVersion: v1 23 kind: Service 24 metadata: 25 name: nginx-service-nodeport 26 spec: 27 ports: 28 - port: 80 29 targetPort: 80 30 protocol: TCP 31 type: NodePort 32 selector: 33 name: nginx1
执行
kubectl apply -f nginx.yaml
还有很多高级命令,如创建、查看、滚动更新、回滚、扩容、缩容,各种集成玩法。
7. 从入门到放弃
k8s真丶从入门到放弃。这个环境配置了两天,我最后可能选择放弃,投入到Rancher的怀抱。
参考资料:
https://blog.csdn.net/qq_21816375/article/details/80222689
https://www.cnblogs.com/omgasw/p/10548334.html
https://blog.csdn.net/ywq935/article/details/80109090
https://my.oschina.net/jianming/blog/2354157
https://blog.csdn.net/oMaoYanEr/article/details/102762654
https://www.cnblogs.com/wjoyxt/p/9988158.html
https://www.jianshu.com/p/63f7f5c021e4
附件下载:https://files.cnblogs.com/files/wunaozai/kube-flannel.zip
本文地址:https://www.cnblogs.com/wunaozai/p/11805259.html
本系列目录: https://www.cnblogs.com/wunaozai/p/8067577.html
个人主页:https://www.wunaozai.com/