配置文件地址:https://docs.projectcalico.org/manifests/calico.yaml
# 上传calico.yaml到k8s-master1上,使用yaml文件安装calico 网络插件 。 [root@k8s-master1 ~]# kubectl apply -f calico.yaml [root@k8s-master1 ~]# kubectl get pod -n kube-system -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES calico-kube-controllers-6949477b58-9t9k8 1/1 Running 0 34s 10.244.159.129 k8s-master1 <none> <none> calico-node-66b47 1/1 Running 0 35s 192.168.40.180 k8s-master1 <none> <none> calico-node-6svrr 1/1 Running 0 35s 192.168.40.182 k8s-node2 <none> <none> calico-node-zgnkl 1/1 Running 0 35s 192.168.40.181 k8s-node1 <none> <none> coredns-7f89b7bc75-4jvmv 1/1 Running 0 28m 10.244.36.65 k8s-node1 <none> <none> coredns-7f89b7bc75-zr5mf 1/1 Running 0 28m 10.244.169.129 k8s-node2 <none> <none> etcd-k8s-master1 1/1 Running 0 28m 192.168.40.180 k8s-master1 <none> <none> kube-apiserver-k8s-master1 1/1 Running 0 28m 192.168.40.180 k8s-master1 <none> <none> kube-controller-manager-k8s-master1 1/1 Running 0 28m 192.168.40.180 k8s-master1 <none> <none> kube-proxy-8fzc4 1/1 Running 0 15m 192.168.40.182 k8s-node2 <none> <none> kube-proxy-n2v4j 1/1 Running 0 28m 192.168.40.180 k8s-master1 <none> <none> kube-proxy-r9ccp 1/1 Running 0 17m 192.168.40.181 k8s-node1 <none> <none> kube-scheduler-k8s-master1 1/1 Running 0 28m 192.168.40.180 k8s-master1 <none> <none> [root@k8s-master1 ~]# kubectl get nodes NAME STATUS ROLES AGE VERSION k8s-master1 Ready control-plane,master 28m v1.20.6 k8s-node1 Ready worker 18m v1.20.6 k8s-node2 Ready worker 15m v1.20.6 # 测试网络连通性 [root@k8s-master1 ~]# kubectl run busybox --image busybox:1.28 --restart=Never --rm -it busybox -- sh If you don\'t see a command prompt, try pressing enter. / # ping baidu.com PING baidu.com (39.156.69.79): 56 data bytes 64 bytes from 39.156.69.79: seq=0 ttl=127 time=43.188 ms 64 bytes from 39.156.69.79: seq=1 ttl=127 time=38.878 ms 2.7、测试部署tomcat服务 [root@k8s-master1 work]# cat tomcat.yaml apiVersion: v1 kind: Pod metadata: name: demo-pod namespace: default labels: app: myapp env: dev spec: containers: - name: tomcat-pod-java ports: - containerPort: 8080 image: tomcat:8.5-jre8-alpine imagePullPolicy: IfNotPresent - name: busybox image: busybox:latest command: - "/bin/sh" - "-c" - "sleep 3600" [root@k8s-master1 work]# cat tomcat-service.yaml apiVersion: v1 kind: Service metadata: name: tomcat spec: type: NodePort ports: - port: 8080 nodePort: 30080 selector: app: myapp env: dev [root@k8s-master1 work]# kubectl apply -f tomcat.yaml pod/demo-pod created [root@k8s-master1 work]# kubectl apply -f tomcat-service.yaml service/tomcat created [root@k8s-master1 work]# kubectl get pods NAME READY STATUS RESTARTS AGE demo-pod 2/2 Running 0 102s [root@k8s-master1 ~]# kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 35m tomcat NodePort 10.106.85.230 <none> 8080:30080/TCP 21s浏览器访问测试:
2.8、测试coredns服务 # busybox要用指定的1.28版本,不能用最新版本,最新版本,nslookup会解析不到dns和ip [root@k8s-master1 ~]# kubectl run busybox --image busybox:1.28 --restart=Never --rm -it busybox -- sh If you don\'t see a command prompt, try pressing enter. / # nslookup kubernetes.default.svc.cluster.local Server: 10.96.0.10 Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local Name: kubernetes.default.svc.cluster.local Address 1: 10.96.0.1 kubernetes.default.svc.cluster.local 三、dashboard部署 3.1、安装dashboard