gpt4 book ai didi

docker - 如何从Kubernetes中的网络新部署的Pod中访问?

转载 作者:行者123 更新时间:2023-12-02 20:14:38 25 4
gpt4 key购买 nike

我是kubernetes的新手,我知道我缺少一些小东西,但是看不到。
我正在使用文件创建Pod:kubectl create -f mysql.yaml

apiVersion: v1
kind: Pod
metadata:
name: mysql
labels:
name: mysql
spec:
containers:
- resources:
limits :
cpu: 2
image: mysql
name: mysql
env:
- name: MYSQL_ROOT_PASSWORD
# change this
value: TestingDB1
ports:
- containerPort: 3306
name: mysql

和以下服务:kubectl create -f mysql_service.yaml
apiVersion: v1
kind: Service
metadata:
labels:
name: mysql
name: mysql
spec:
externalIPs:
- 10.19.13.127
ports:
- port: 3306
selector:
name: mysql

“kubectl版本”的输出
Client Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.2", GitCommit:"d33fd89e399396658aed4e48dfe7d5d8d50ac6e8", GitTreeState:"clean", BuildDate:"2017-05-26T17:08:24Z", GoVersion:"go1.7.4", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.2", GitCommit:"d33fd89e399396658aed4e48dfe7d5d8d50ac6e8", GitTreeState:"clean", BuildDate:"2017-05-26T17:08:24Z", GoVersion:"go1.7.4", Compiler:"gc", Platform:"linux/amd64"}

“kubectl cluster-info”的输出
Kubernetes master is running at http://localhost:8080

“kubectl get pods”的输出
NAME                    READY     STATUS    RESTARTS   AGE
mysql 1/1 Running 0 20m

“kubectl get svc”的输出
NAME         CLUSTER-IP       EXTERNAL-IP    PORT(S)    AGE
kubernetes 10.254.0.1 <none> 443/TCP 18h
mysql 10.254.129.206 10.19.13.127 3306/TCP 1h

输出“kubectl get no”
NAME           STATUS    AGE
10.19.13.127 Ready 19h

“docker ps”的输出
CONTAINER ID        IMAGE                                      COMMAND                  CREATED             STATUS              PORTS               NAMES
74ea1fb2b383 mysql "docker-entrypoint.sh" 3 minutes ago Up 3 minutes k8s_mysql.ae7893ad_mysql_default_e58d1c09-4a8e-11e7-9baf-fa163ee3f5d9_793d8d7c

我可以看到Pod正在正常创建。即使当我连接到容器时,我也可以使用凭据登录mysql。

我的问题是:
如何从网络访问/暴露在kubernetes节点上运行的端口?例如,我想从我的PC到运行mysql pod的kubernetes节点建立telnet。

谢谢 !

最佳答案

在Command下面,验证Redis服务器是否在Pod中运行并且正在侦听哪个端口(通常在6379端口上运行):

kubectl get pods redis-master --template ='{{(index(index .spec.containers 0).ports 0).containerPort}} {{“\ n”}}'

输出:6739

关于docker - 如何从Kubernetes中的网络新部署的Pod中访问?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44384792/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com