IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 网络协议 -> ubuntu20.04下使用juju+maas环境部署k8s-10-基本操作-2-访问在集群内运行 Web 服务的容器 -> 正文阅读

[网络协议]ubuntu20.04下使用juju+maas环境部署k8s-10-基本操作-2-访问在集群内运行 Web 服务的容器

参考文档:

Basic operations

kubernetes如何访问pod服务

k8s 如何对外提供服务

Kubernetes dashboard 通过 Ingress 提供HTTPS访问

接上文:ubuntu20.04下使用juju+maas环境部署k8s-8-基本操作-1-访问 kubernetes dashboard

k8s 向外提供服务有几种办法:
1 port-foward
2 node-port
3 ingress

port-forward方法:

例如,有个pod 叫做microbot-75cfc77b98-58rqh ,它通过80端口对外提供服务,那么我就可以使用kubectl port-forward pod/microbot-75cfc77b98-58rqh 8080:80将其映射到本机的8080端口上。你可以使用kubectl port-forward -h查看更多用法。

查看服务:

kubectl get svc
NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
kubernetes   ClusterIP   10.152.183.1     <none>        443/TCP          34d
microbot     ClusterIP   10.152.183.8     <none>        80/TCP           2d1h
web          NodePort    10.152.183.239   <none>        8080:31961/TCP   23d

查看pod

 kubectl get pod
NAME                        READY   STATUS    RESTARTS   AGE
microbot-75cfc77b98-58rqh   1/1     Running   0          2d1h
microbot-75cfc77b98-h2ttn   1/1     Running   0          2d1h
microbot-75cfc77b98-zt5rx   1/1     Running   0          2d1h

端口映射:

 kubectl port-forward pod/microbot-75cfc77b98-58rqh 8080:80 &

查看链接:

 curl http://localhost:8080
Handling connection for 8080
<!DOCTYPE html>
<html>
  <style type="text/css">
    .centered
      {
      text-align:center;
      margin-top:0px;
      margin-bottom:0px;
      padding:0px;
      }
  </style>
  <body>
    <p class="centered"><img src="microbot.png" alt="microbot"/></p>
    <p class="centered">Container hostname: microbot-75cfc77b98-58rqh</p>
  </body>
</html>

Ingress方法:

查看服务:

kubectl get svc
NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
kubernetes   ClusterIP   10.152.183.1     <none>        443/TCP          33d
microbot     ClusterIP   10.152.183.8     <none>        80/TCP           22h
web          NodePort    10.152.183.239   <none>        8080:31961/TCP   21d

查看服务microbot:

kubectl get svc microbot -o wide
NAME       TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)   AGE   SELECTOR
microbot   ClusterIP   10.152.183.8   <none>        80/TCP    22h   app=microbot

查看详细的microbot服务内容:

 kubectl describe svc microbot
Name:              microbot
Namespace:         default
Labels:            app=microbot
Annotations:       <none>
Selector:          app=microbot
Type:              ClusterIP
IP Family Policy:  SingleStack
IP Families:       IPv4
IP:                10.152.183.8
IPs:               10.152.183.8
Port:              <unset>  80/TCP
TargetPort:        80/TCP
Endpoints:         10.1.50.8:80,10.1.89.10:80,10.1.89.9:80
Session Affinity:  None
Events:            <none>

在kubernetes-dashboard中查看ingress的配置:



kind: Ingress
apiVersion: networking.k8s.io/v1beta1
metadata:
  name: microbot-ingress
  namespace: default
  uid: e8d52971-8263-4875-8b1a-2016b711e99a
  resourceVersion: '4594539'
  generation: 1
  creationTimestamp: '2021-08-04T07:14:24Z'
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: >
      {"apiVersion":"networking.k8s.io/v1","kind":"Ingress","metadata":{"annotations":{},"name":"microbot-ingress","namespace":"default"},"spec":{"rules":[{"host":"microbot.10.0.4.18.nip.io","http":{"paths":[{"backend":{"service":{"name":"microbot","port":{"number":80}}},"path":"/","pathType":"Prefix"}]}}]}}
  managedFields:
    - manager: kubectl-client-side-apply
      operation: Update
      apiVersion: networking.k8s.io/v1
      time: '2021-08-04T07:14:24Z'
      fieldsType: FieldsV1
      fieldsV1:
        f:metadata:
          f:annotations:
            .: {}
            f:kubectl.kubernetes.io/last-applied-configuration: {}
        f:spec:
          f:rules: {}
    - manager: nginx-ingress-controller
      operation: Update
      apiVersion: networking.k8s.io/v1beta1
      time: '2021-08-04T07:14:27Z'
      fieldsType: FieldsV1
      fieldsV1:
        f:status:
          f:loadBalancer:
            f:ingress: {}
spec:
  rules:
    - host: microbot.10.0.4.18.nip.io
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              serviceName: microbot
              servicePort: 80
status:
  loadBalancer:
    ingress:
      - ip: 10.0.4.18
      - ip: 10.0.4.19
      - ip: 10.0.4.22

命令查看ingress

 kubectl get ingress
NAME               CLASS    HOSTS                       ADDRESS                         PORTS   AGE
microbot-ingress   <none>   microbot.10.0.4.18.nip.io   10.0.4.18,10.0.4.19,10.0.4.22   80      22h
kubectl describe ingress microbot-ingress
Name:             microbot-ingress
Namespace:        default
Address:          10.0.4.18,10.0.4.19,10.0.4.22
Default backend:  default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
Rules:
  Host                       Path  Backends
  ----                       ----  --------
  microbot.10.0.4.18.nip.io
                             /   microbot:80 (10.1.50.8:80,10.1.89.10:80,10.1.89.9:80)
Annotations:                 <none>
Events:                      <none>

查看namespace

 kubectl get ns
NAME                              STATUS   AGE
default                           Active   33d
ingress-nginx-kubernetes-worker   Active   33d
kube-node-lease                   Active   33d
kube-public                       Active   33d
kube-system                       Active   33d
kubernetes-dashboard              Active   33d

查看namespace default 中pod

kubectl describe pod -n default
Name:         microbot-75cfc77b98-58rqh
Namespace:    default
Priority:     0
Node:         moral-locust/10.0.4.22
Start Time:   Wed, 04 Aug 2021 15:14:25 +0800
Labels:       app=microbot
              pod-template-hash=75cfc77b98
Annotations:  kubernetes.io/psp: privileged
Status:       Running
IP:           10.1.89.9
IPs:
  IP:           10.1.89.9
Controlled By:  ReplicaSet/microbot-75cfc77b98
Containers:
  microbot:
    Container ID:   containerd://fee49d008623358f69f9b772b4389ded608db7d4f57c7065c029ca2a622980bf
    Image:          rocks.canonical.com:443/cdk/cdkbot/microbot-amd64:latest
    Image ID:       rocks.canonical.com:443/cdk/cdkbot/microbot-amd64@sha256:9c949ba3afdb530eaa3a6e6e67126bd7543e4a21b092384e431246dd0141d6c1
    Port:           80/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Wed, 04 Aug 2021 15:14:30 +0800
    Ready:          True
    Restart Count:  0
    Liveness:       http-get http://:80/ delay=5s timeout=30s period=10s #success=1 #failure=3
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-znxkc (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             True
  ContainersReady   True
  PodScheduled      True
Volumes:
  kube-api-access-znxkc:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:                      <none>


Name:         microbot-75cfc77b98-h2ttn
Namespace:    default
Priority:     0
Node:         moral-locust/10.0.4.22
Start Time:   Wed, 04 Aug 2021 15:14:25 +0800
Labels:       app=microbot
              pod-template-hash=75cfc77b98
Annotations:  kubernetes.io/psp: privileged
Status:       Running
IP:           10.1.89.10
IPs:
  IP:           10.1.89.10
Controlled By:  ReplicaSet/microbot-75cfc77b98
Containers:
  microbot:
    Container ID:   containerd://3ebdee79058a395f5adcab46085a2dfa5334de975cafff65c6f6a56af26e1d8d
    Image:          rocks.canonical.com:443/cdk/cdkbot/microbot-amd64:latest
    Image ID:       rocks.canonical.com:443/cdk/cdkbot/microbot-amd64@sha256:9c949ba3afdb530eaa3a6e6e67126bd7543e4a21b092384e431246dd0141d6c1
    Port:           80/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Wed, 04 Aug 2021 15:14:33 +0800
    Ready:          True
    Restart Count:  0
    Liveness:       http-get http://:80/ delay=5s timeout=30s period=10s #success=1 #failure=3
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-xmxln (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             True
  ContainersReady   True
  PodScheduled      True
Volumes:
  kube-api-access-xmxln:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:                      <none>


Name:         microbot-75cfc77b98-zt5rx
Namespace:    default
Priority:     0
Node:         crack-raptor/10.0.4.18
Start Time:   Wed, 04 Aug 2021 15:14:25 +0800
Labels:       app=microbot
              pod-template-hash=75cfc77b98
Annotations:  kubernetes.io/psp: privileged
Status:       Running
IP:           10.1.50.8
IPs:
  IP:           10.1.50.8
Controlled By:  ReplicaSet/microbot-75cfc77b98
Containers:
  microbot:
    Container ID:   containerd://6c9a3dcc859e080911a75363cee9b497f3ee7d0f9f0af190ac7bb0687bdc80f6
    Image:          rocks.canonical.com:443/cdk/cdkbot/microbot-amd64:latest
    Image ID:       rocks.canonical.com:443/cdk/cdkbot/microbot-amd64@sha256:9c949ba3afdb530eaa3a6e6e67126bd7543e4a21b092384e431246dd0141d6c1
    Port:           80/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Wed, 04 Aug 2021 15:14:33 +0800
    Ready:          True
    Restart Count:  0
    Liveness:       http-get http://:80/ delay=5s timeout=30s period=10s #success=1 #failure=3
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-zz444 (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             True
  ContainersReady   True
  PodScheduled      True
Volumes:
  kube-api-access-zz444:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:                      <none>

编辑本机的 /etc/hosts

vim /etc/hosts

10.0.4.18  microbot.10.0.4.18.nip.io

重启网络服务

netplan apply

测试链接:

curl microbot.10.0.4.18.nip.io

<!DOCTYPE html>
<html>
  <style type="text/css">
    .centered
      {
      text-align:center;
      margin-top:0px;
      margin-bottom:0px;
      padding:0px;
      }
  </style>
  <body>
    <p class="centered"><img src="microbot.png" alt="microbot"/></p>
    <p class="centered">Container hostname: microbot-75cfc77b98-58rqh</p>
  </body>
</html>
root@vivodo-3:~# curl 10.0.4.18
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html>
  网络协议 最新文章
使用Easyswoole 搭建简单的Websoket服务
常见的数据通信方式有哪些?
Openssl 1024bit RSA算法---公私钥获取和处
HTTPS协议的密钥交换流程
《小白WEB安全入门》03. 漏洞篇
HttpRunner4.x 安装与使用
2021-07-04
手写RPC学习笔记
K8S高可用版本部署
mySQL计算IP地址范围
上一篇文章      下一篇文章      查看所有文章
加:2021-08-07 12:25:58  更:2021-08-07 12:26:21 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/25 18:51:38-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码