# my-first-pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: my-pod
labels:
app: webserver
spec:
containers:
- name: pod-demo
image: baoguoding/demo
ports:
- containerPort: 3000
kubectl create -f my-first-pod.yaml
kubectl get pods -n default
kubectl get pods --show-all
kubectl describe pod my-pod -n default
yum install socat
kubectl port-forward my-pod 8000:3000
kubectl expose pod my-pod --type=NodePort --name=my-pod-service
kubectl get services
kubectl describe service my-pod-service
[root@VM_0_12_centos ~]# kubectl get pods --all-namespaces -o wide
NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE
default my-pod 1/1 Running 0 49m 192.168.45.2 172.27.0.17 <none>
[root@VM_0_12_centos yaml]# kubectl expose pod my-pod --type=NodePort --name=my-pod-service
service/my-pod-service exposed
[root@VM_0_12_centos yaml]# kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 192.17.17.1 <none> 443/TCP 1h
my-pod-service NodePort 192.17.17.239 <none> 3000:31482/TCP 13s
[root@VM_0_12_centos yaml]# curl 127.0.0.1:31482
Hello World![root@VM_0_12_centos yaml]# curl 127.0.0.1:31482
Hello World![root@VM_0_12_centos yaml]# kubectl get ep
NAME ENDPOINTS AGE
kubernetes 172.27.0.12:6443 1h
my-pod-service 192.168.45.2:3000 2m
[root@VM_0_12_centos yaml]# kubectl describe service my-pod-service
Name: my-pod-service
Namespace: default
Labels: app=webserver
Annotations: <none>
Selector: app=webserver
Type: NodePort
IP: 192.17.17.239
Port: <unset> 3000/TCP
TargetPort: 3000/TCP
NodePort: <unset> 31482/TCP
Endpoints: 192.168.45.2:3000
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
kubectl get pods
kubectl get pods --show-all
kubectl describe pod <pod>
kubectl expose pod <pod> --port=<port> --name=<service-name>
kubectl port-forward <pod> <external-port>:<pod-port>
kubectl label pods <pod> <label-key>=<label-value>
kubectl get pods --show-labels
参考