kubernetes网络访问测试

1.网络请求测试
创建deploment控制器
kubectl run nginx-deploy --image=nginx:1.14-alpine --port=80 --replicas=1

    [root@k8s-master /]# kubectl get pod -o wide
    NAME                            READY   STATUS    RESTARTS   AGE   IP            NODE        NOMINATED NODE   READINESS GATES
    client                          1/1     Running   0          32m   10.244.2.11   k8s-node2   <none>           <none>
    nginx-deploy-66ff98548d-xvbw8   1/1     Running   0          18s   10.244.1.17   k8s-node1   <none>           <none>

其中pod节点IP 属于节点的cni0桥网络 集群内的pod节点互相可以解析
创建service暴露nginx服务端口
kubectl expose deploy nginx-deploy --name=nginx --port=80 --target-port=80

    [root@k8s-master /]# kubectl get svc
    NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)   AGE
    kubernetes   ClusterIP   10.96.0.1        <none>        443/TCP   13d
    nginx        ClusterIP   10.106.160.157   <none>        80/TCP    7s

CLUSTER-IP 集群IP可以被集群节点curl访问
nginx 服务可以被解析成集群ClusterIP
dig -t A nginx.default.svc.cluster.local @10.96.0.10

    ;; ANSWER SECTION:
    nginx.default.svc.cluster.local. 30 IN  A       10.106.160.157

创建一个pod客户端测试访问其他节点
kubectl run client --image=busybox --replicas=1 -it --restart=Never

/ # wget nginx
Connecting to nginx (10.106.160.157:80)
saving to 'index.html'
index.html           100% |******************************************************************************************************************************************|   612  0:00:00 ETA
'index.html' saved

pod节点可以访问其他pod节点服务并解析成对应的ClusterIP以及端口

通过service通过标签关联pod

[root@k8s-master /]# kubectl get pods --show-labels
NAME                            READY   STATUS    RESTARTS   AGE   LABELS
client                          1/1     Running   0          82m   run=client
nginx-deploy-66ff98548d-xvbw8   1/1     Running   0          49m   pod-template-hash=66ff98548d,run=nginx-deploy

[root@k8s-master /]# kubectl describe svc nginx
Name:              nginx
Namespace:         default
Labels:            run=nginx-deploy
Annotations:       <none>
Selector:          run=nginx-deploy
Type:              ClusterIP
IP:                10.106.160.157
Port:              <unset>  80/TCP
TargetPort:        80/TCP
Endpoints:         10.244.1.17:80
Session Affinity:  None
Events:            <none>

2.启动一个简单的应用的命令
kubectl run nginx-deploy --image=nginx:1.14-alpine --port=80 --replicas=1
kubectl expose deploy nginx-deploy --name=nginx --port=80 --target-port=80
kubectl run client --image=busybox --replicas=1 -it --restart=Never
kubectl get pod -w
kubectl set image deployment myapp myapp=ikubernetes/myapp:v2
kubectl scale --replicas=5 deployment myapp
kubectl rollout status deployment myapp
kubectl get pod pod_name -o yaml
kubectl edit deployment nginx-deploy
kubectl get pods --show-labels

上一篇:kubernetes 控制器


下一篇:【Gitlab】集成自动化部署PHP代码