k8s集群搭建

1、主流程参考链接:http://www.mfbz.cn/a/128766.html

校正:下载docker-cri地址:https://github.com/Mirantis/cri-dockerd/releases

 

2、子节点获取节点报错:E0308 16:47:17.812414    9813 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp 127.0.0.1:8080: connect: connection refused

参考:https://www.cnblogs.com/sky-cheng/p/14239549.html

 

3、搭建运行nginx

3.1 创建deployment

vim /k8s_workspace/deployments/nginx.yml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - containerPort: 80

 

3.2 创建service

vim /k8s_workspace/services/nginx.yml

apiVersion: v1
kind: Service
metadata:
  name: nginx
spec:
  selector:
    app: nginx
  ports:
    - protocol: TCP
      port: 18080
      targetPort: 80
  type: LoadBalancer

 

3.3 启动

kubectl apply -f /k8s_workspace/services/nginx.yml

kubectl apply -f /k8s_workspace/deployments/nginx.yml 

 

3.4 查看

kubectl get pods 

发现pod一直无法启动,查看日志无法找到有用信息(kubectl --tail=200 logs -f /k8s_workspace/deployments/nginx.yml)

kubectl describe pod xxx

发现报错:network: plugin type="flannel" failed (add): loadFlannelSubnetEnv failed: open /run/flannel/subnet.env: no such file or directory

解决方案:vim /run/flannel/subnet.env

FLANNEL_NETWORK=10.1.0.0/16
FLANNEL_SUBNET=10.1.0.1/24
FLANNEL_MTU=1450
FLANNEL_IPMASQ=true

 

3.5 访问 curl localhost:18080 无法访问

进入容器访问:

kubectl exec -it nginx-6b7f675859-mvx44 -- /bin/bash

curl 10.1.0.5

发现访问正常、查看pod坐在的节点后发现在另一台设备上、需要使用

 

 

curl node2IP:PORT2(curl 192.168.2.84:32158) 访问是ok的、此时service的type为LoadBalancer

同时service的type为NodePort 与上述方式一直

 4、kubelet ingress-nginx搭建

1、下载安装ingress-nginx-controller等的配置文件
curl -O https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.10.0/deploy/static/provider/cloud/deploy.yaml

2、修改配置
#默认的namespace由默认的ingress-nginx改成了test,我指定的命名空间
sed -i 's/namespace: ingress-nginx/namespace: default/g' deploy.yaml
#配置文件修改成阿里的镜像地址了image: registry.cn-hangzhou.aliyuncs.com/google_containers
sed -i 's/registry.k8s.io\/ingress-nginx/registry.cn-hangzhou.aliyuncs.com\/google_containers/g' deploy.yaml
sed -i 's/@sha256:44d1d0e9f19c63f58b380c5fddaca7cf22c7cee564adeff365225a5df5ef3334//g' deploy.yaml #第三处修改(ingress
-nginx-controller的Service默认的type是LoadBalancer,我们修改成NodePort) sed -i 's/LoadBalancer/NodePort/g' deploy.yaml
#第四处修改(ingress
-nginx-controller的Deployment的配置中加上了hostNetwork: true,设置hostNetwork为true的容器将能够访问宿主机上的任何网络接口和端口,并且可以通过宿主机的IP地址与其他计 template下的 spec: hostNetwork: true

 

posted @ 2024-03-08 17:10  漂渡  阅读(62)  评论(0编辑  收藏  举报