## First get the all pods info.
kubectl get pods -owide
## Create a Service and a Pod
kubectl create service clusterip cce21days-app5-svc-mikeliu2018 --tcp=80:8080
kubectl get svc
kubectl run cce21days-app5-pod-mikeliu2018 --image=nginx
kubectl get pods
## Expose the Pod and we can get the info. by the curl command
kubectl get endpoints
kubectl expose deployment cce21days-app5-pod-mikeliu2018 --type=ClusterIP --name=cce21days-app5-endpoint-mikeliu2018 --port=8090 --target-port=80
kubectl get endpoints
curl IPaddress:Ports
## Install the busybox pod for the nslookup Service. and the image version: 1.28 and te parameters sleep 3600
wget https://kubernetes.io/examples/admin/dns/busybox.yaml
kubectl create -f busybox.yaml
## The Content of busybox.yaml Please reference the end
## resolve the pod info.
kubectl exec -it busybox -- nslookup kubernetes.default
## Check the result info.
kubectl describe svc cce21days-app5-svc-mikeliu2018
kubectl describe svc cce21days-app5-endpoint-mikeliu2018
kubectl describe endpoints cce21days-app5-svc-mikeliu2018
kubectl describe endpoints cce21days-app5-endpoint-mikeliu2018
## The Content of Endpoint.yaml
{
kind: Service
apiVersion: v1
metadata:
name: cce21days-app5-endpoint-mikeliu2018
namespace: default
selfLink: /api/v1/namespaces/default/services/cce21days-app5-endpoint-mikeliu2018
uid: d4b0e2cb-fdd8-11e8-b1db-fa163e9d962e
resourceVersion: '299076'
creationTimestamp: '2018-12-12T06:40:35Z'
labels:
run: cce21days-app5-pod-mikeliu2018
spec:
ports:
- protocol: TCP
port: 8090
targetPort: 80
selector:
run: cce21days-app5-pod-mikeliu2018
clusterIP: 10.247.221.118
type: ClusterIP
sessionAffinity: None
status:
loadBalancer: {}
}
## The Content of Service.yaml
{
kind: Service
apiVersion: v1
metadata:
name: cce21days-app5-svc-mikeliu2018
namespace: default
selfLink: /api/v1/namespaces/default/services/cce21days-app5-svc-mikeliu2018
uid: bc8b1e35-fdd8-11e8-be9d-fa163e7484bb
resourceVersion: '298975'
creationTimestamp: '2018-12-12T06:39:55Z'
labels:
app: cce21days-app5-svc-mikeliu2018
spec:
ports:
- name: 80-8080
protocol: TCP
port: 80
targetPort: 8080
selector:
app: cce21days-app5-svc-mikeliu2018
clusterIP: 10.247.78.154
type: ClusterIP
sessionAffinity: None
status:
loadBalancer: {}
}
## The busybox.yaml file
{
kind: Pod
apiVersion: v1
metadata:
name: busybox
namespace: default
selfLink: /api/v1/namespaces/default/pods/busybox
uid: 19882276-fdd6-11e8-bfe5-fa163edc93ee
resourceVersion: '311720'
creationTimestamp: '2018-12-12T06:21:02Z'
annotations:
kubernetes.io/availablezone: cn-north-1a
spec:
volumes:
- name: default-token-hkz57
secret:
secretName: default-token-hkz57
defaultMode: 420
containers:
- name: busybox
image: 'busybox:1.28'
command:
- sleep
- '3600'
resources: {}
volumeMounts:
- name: default-token-hkz57
readOnly: true
mountPath: /var/run/secrets/kubernetes.io/serviceaccount
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: IfNotPresent
restartPolicy: Always
terminationGracePeriodSeconds: 30
dnsPolicy: ClusterFirst
serviceAccountName: default
serviceAccount: default
nodeName: 192.168.73.129
securityContext: {}
schedulerName: default-scheduler
tolerations:
- key: node.kubernetes.io/not-ready
operator: Exists
effect: NoExecute
tolerationSeconds: 300
- key: node.kubernetes.io/unreachable
operator: Exists
effect: NoExecute
tolerationSeconds: 300
status:
phase: Running
conditions:
- type: Initialized
status: 'True'
lastProbeTime: null
lastTransitionTime: '2018-12-12T06:21:02Z'
- type: Ready
status: 'True'
lastProbeTime: null
lastTransitionTime: '2018-12-12T08:21:08Z'
- type: PodScheduled
status: 'True'
lastProbeTime: null
lastTransitionTime: '2018-12-12T06:21:02Z'
hostIP: 192.168.73.129
podIP: 172.16.0.58
startTime: '2018-12-12T06:21:02Z'
containerStatuses:
- name: busybox
state:
running:
startedAt: '2018-12-12T08:21:08Z'
lastState:
terminated:
exitCode: 0
reason: Completed
startedAt: '2018-12-12T07:21:06Z'
finishedAt: '2018-12-12T08:21:06Z'
containerID: >-
docker://8f0dd58c8be1eb637490e618e7c1e068246321cb40b45c5f7d3ad7ba253dba4f
ready: true
restartCount: 2
image: 'busybox:1.28'
imageID: >-
docker-pullable://busybox@sha256:74f634b1bc1bd74535d5209589734efbd44a25f4e2dc96d78784576a3eb5b335
containerID: >-
docker://e9fd24c7e19b1004ead0aedd63482c22a923756dfff6d84f2a7551222fcd5e71
qosClass: BestEffort
managementIP: 192.168.73.129
}
评论0