service/kubernetes-bootcamp exposed

$ kubectl get services

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE

kubernetes ClusterIP 10.96.0.1 443/TCP 19m

kubernetes-bootcamp NodePort 10.97.109.177 8080:32724/TCP 28s

我们现在有了一个名为 kubernetes-bootcamp 的运行服务。在这里,我们看到服务接收到一个唯一的集群IP、一个内部端口和一个外部IP(节点的IP)。


要了解外部(通过NodePort选项)打开了哪个端口,我们将运行descripe service命令:

$ kubectl describe services/kubernetes-bootcamp

Name: kubernetes-bootcamp

Namespace: default

Labels: app=kubernetes-bootcamp

Annotations:

Selector: app=kubernetes-bootcamp

Type: NodePort

IP Families:

IP: 10.97.109.177

IPs: 10.97.109.177

Port: 8080/TCP

TargetPort: 8080/TCP

NodePort: 32724/TCP

Endpoints: 172.18.0.6:8080

Session Affinity: None

External Traffic Policy: Cluster

Events:


创建一个名为NODE_PORT的环境变量,该变量指定了节点端口的值:

$ export NODE_PORT=$(kubectl get services/kubernetes-bootcamp -o go-template=‘{{(index .spec.ports 0).nodePort}}’)

$ echo NODE_PORT=$NODE_PORT

NODE_PORT=32724

现在,我们可以使用curl、节点的IP和外部暴露的端口来测试应用是否暴露在集群之外:

$ curl ( m i n i k u b e i p ) : (minikube ip): (minikubeip):NODE_PORT

Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-fb5c67579-wbqtf | v=1

我们得到了服务器的响应。该服务已公开。


部署自动为我们的 Pod 创建了一个标签。使用 “describe deployment” 命令,可以看到标签的名称:

$ kubectl describe deployment

Name: kubernetes-bootcamp

Namespace: default

CreationTimestamp: Sat, 29 Jan 2022 06:33:50 +0000

Labels: app=kubernetes-bootcamp

Annotations: deployment.kubernetes.io/revision: 1

Selector: app=kubernetes-bootcamp

Replicas: 1 desired | 1 updated | 1 total | 1 available | 0 unavailable

StrategyType: RollingUpdate

MinReadySeconds: 0

RollingUpdateStrategy: 25% max unavailable, 25% max surge

Pod Template:

Labels: app=kubernetes-bootcamp

Containers:

kubernetes-bootcamp:

Image: gcr.io/google-samples/kubernetes-bootcamp:v1

Port: 8080/TCP

Host Port: 0/TCP

Environment:

Mounts:

Volumes:

Conditions:

Type Status Reason


Available True MinimumReplicasAvailable

Progressing True NewReplicaSetAvailable

OldReplicaSets:

NewReplicaSet: kubernetes-bootcamp-fb5c67579 (1/1 replicas created)

Events:

Type Reason Age From Message


Normal ScalingReplicaSet 24m deployment-controller Scaled up replica set kubernetes-bootcamp-fb5c67579 to 1


让我们使用这个标签来查询POD列表。我们将使用kubectl get pods命令,参数为-l,后面是标签值:

$ kubectl get pods -l app=kubernetes-bootcamp

NAME READY STATUS RESTARTS AGE

kubernetes-bootcamp-fb5c67579-wbqtf 1/1 Running 0 26m

也可以这样列出现有服务:

$ kubectl get services -l app=kubernetes-bootcamp

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE

kubernetes-bootcamp NodePort 10.97.109.177 8080:32724/TCP 8m46s


获取Pod的名称并将其存储在Pod_name环境变量中:

$ export POD_NAME=$(kubectl get pods -o go-template --template ‘{{range .items}}{{.metadata.name}}{{“\n”}}{{end}}’)

$ echo Name of the Pod: $POD_NAME

Name of the Pod: kubernetes-bootcamp-fb5c67579-wbqtf


要应用新标签,我们使用label命令,后跟对象类型、对象名称和新标签:

$ kubectl label pods $POD_NAME version=v1

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐