linux怎么查看本机内存大小
290
2022-10-01
kubernetes v1.23 集群快速安装
当前安装环境有三台:一台master,两台node节点 ,非高可用,适用于学习/测试环境下的快速拉起一个k8s集群使用。
前提: docker配置 cgroupdriver=systemd
cat < 一、各节点安装基础包 sudo apt-get updatesudo apt-get install -y apt-transport-ca-certificates curlsudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.listsudo apt-get updatesudo apt install kubeadm=1.23.0-00 kubelet=1.23.0-00 kubectl=1.23.0-00sudo apt-mark hold kubelet kubeadm kubectl 二、master上执行初始化 方式一:使用命令行参数执行init: kubeadm init -h kubeadm init --pod-network-cidr=172.22.0.0/16 --kubernetes-version=1.23.0 --image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers --service-cidr=10.92.0.0/16 参数说明: --pod-network-cidr:自定义Pod的网段CIDR格式,应该与网络插件的Pod网段相同。--kubernetes-version: 指定安装的kubernetes版本,默认是与kubeadm版本相同的最新子版本号。--image-repository: 指定拉取各组件的镜像地址为阿里云仓库,默认是k8s.gcr.io。--service-cidr:自定义Service ClusterIP的网段CIDR格式。 方式二: 使用一个配置文件来执行init apiVersion: kubeadm.k8s.io/v1beta3kind: InitConfigurationnodeRegistration:#运行时改成了containerd criSocket: /run/containerd/containerd.sock imagePullPolicy: IfNotPresent---apiServer: timeoutForControlPlane: 4m0sapiVersion: kubeadm.k8s.io/v1beta3certificatesDir: /etc/kubernetes/pkiclusterName: kubernetescontrollerManager: {}dns: {}etcd: local: dataDir: /var/lib/etcdimageRepository: registry.cn-hangzhou.aliyuncs.com/google_containerskind: ClusterConfigurationkubernetesVersion: 1.23.0controlPlaneEndpoint: "10.1.13.134:6443"networking: dnsDomain: cluster.local serviceSubnet: 10.92.0.0/16 podSubnet: 172.22.0.0/16 #然后执行init kubeadm init --config kubeadm-init.yaml --upload-certs 下面是输出结果: mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/configAlternatively, if you are the root user, you can run: export KUBECONFIG=/etc/kubernetes/admin.confYou should now deploy a pod network to the cluster.Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at: you can join any number of worker nodes by running the following on each as root:#将下面这句复制出来,在节点加入集群时使用kubeadm join 10.1.13.98:6443 --token myz8np.97lnvlka60xdlvmt \ --discovery-token-ca-cert-hash sha256:473eb3870f856d3dca8afc388011f586b7ab72f8d61ddcf23bce8c504834a896 三、node 节点 加入集群 #两台node节点都执行kubeadm join 10.1.13.98:6443 --token myz8np.97lnvlka60xdlvmt \--discovery-token-ca-cert-hash sha256:473eb3870f856d3dca8afc388011f586b7ab72f8d61ddcf23bce8c504834a896 由于还没安装网络插件,所以各Node暂未Ready: $ kubectl get nodeNAME STATUS ROLES AGE VERSIONtest-node-tmp-1 NotReady control-plane,master 4m50s v1.23.0test-node-tmp-2 NotReady 49s v1.23.0test-node-tmp-3 NotReady 45s v1.23.0 四、安装Flannel 项目地址:--pod-network-cidr 参数的值相同: wget vi kube-flannel.ymlnet-conf.json: | { "Network": "172.22.0.0/16", "Backend": { "Type": "vxlan" } } `然后应用到集群: kubectl apply -f kube-flannel.yml 然后,各Node状态Ready: $ kubectl get nodeNAME STATUS ROLES AGE VERSIONtest-node-tmp-1 Ready control-plane,master 10m v1.23.0test-node-tmp-2 Ready 8m43s v1.23.0test-node-tmp-3 Ready 8m38s v1.23.0 五、集群验证 配置kubectl的命令补全功能 #永久生效$ source <(kubectl completion bash)#当前生效$ echo "source <(kubectl completion bash)" >> ~/.bashrc 测试集群 cat nginx-deploy.yamlapiVersion: apps/v1kind: Deploymentmetadata: name: nginx-deploymentspec: selector: matchLabels: app: nginx replicas: 2 # tells deployment to run 2 pods matching the template template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.10 ports: - containerPort: 80---apiVersion: v1kind: Servicemetadata: name: nginx namespace: defaultspec: selector: app: nginx ports: - protocol: TCP port: 80 name: kubectl apply -f nginx-deploy.yaml$ kubectl get pod -o wideNAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATESnginx-deployment-748755bf57-fwg65 1/1 Running 0 34s 172.22.2.3 test-node-tmp-3 nginx-deployment-748755bf57-mnh9v 1/1 Running 0 34s 172.22.2.4 test-node-tmp-3 $ kubectl get svcNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEkubernetes ClusterIP 10.92.0.1 443/TCP 34mnginx ClusterIP 10.92.15.234 80/TCP 41s//访问podIP curl -I 172.22.2.4HTTP/1.1 200 OKServer: nginx/1.10.3Date: Fri, 19 Nov 2021 10:02:20 GMTContent-Type: text/htmlContent-Length: 612Last-Modified: Tue, 31 Jan 2017 15:01:11 GMTConnection: keep-aliveETag: "5890a6b7-264"Accept-Ranges: bytes//访问ClusterIP$ curl -I 10.92.15.234HTTP/1.1 200 OKServer: nginx/1.10.3Date: Fri, 19 Nov 2021 10:03:26 GMTContent-Type: text/htmlContent-Length: 612Last-Modified: Tue, 31 Jan 2017 15:01:11 GMTConnection: keep-aliveETag: "5890a6b7-264"Accept-Ranges: bytes``` 集群部署完毕!
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~