Exercise 1
Creating a Service and a Pod as its backend. The information obtained by the Service and the corresponding Endpoints kubectl describe.
- Name Service for
<hwcka-004-1-svc-你的华为云id>
- Pod name is
<hwcka-004-1-pod-你的华为云id>
- The full command used yaml shots, Service Endpoints and upload
First create a pod, pay attention to add tags. Because Pod and Service will associate by the label.
[root@svn ch4]# cat pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: hwcka-004-1-pod-joyo
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:alpine
[root@svn ch4]# kubectl apply -f pod.yaml
pod/hwcka-004-1-pod-joyo created
[root@svn ch4]# kubectl get pod
NAME READY STATUS RESTARTS AGE
busybox 1/1 Running 13 20h
hwcka-004-1-pod-joyo 1/1 Running 0 13s
[root@svn ch4]#
Subsequently the pod is exposed service
kubectl expose pod hwcka-004-1-pod-joyo --port=8888 --target-port=80 --name=hwcka-004-1-svc-joyo
Testing and validation:
[root@svn ch4]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hwcka-004-1-svc-joyo ClusterIP 10.101.211.222 <none> 8888/TCP 4m19s
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 41d
[root@svn ch4]# kubectl get ep
NAME ENDPOINTS AGE
hwcka-004-1-svc-joyo 10.244.2.179:80 8m22s
kubernetes 192.168.202.130:6443 41d
[root@svn ch4]# k describe svc hwcka-004-1-svc-joyo
Name: hwcka-004-1-svc-joyo
Namespace: default
Labels: app=nginx
Annotations: <none>
Selector: app=nginx
Type: ClusterIP
IP: 10.101.211.222
Port: <unset> 8888/TCP
TargetPort: 80/TCP
Endpoints: 10.244.2.179:80
Session Affinity: None
Events: <none>
And running curl 10.244.2.179:80
and curl 10.101.211.222:8888
can see the Welcome to nginx!
welcome page.
English II
Creating a Service and a Pod as its backend. Pod nslookup query by the Service of domain name information.
- Name Service for
<hwcka-004-2-你的华为云id>
- The command, Service and upload the screenshot Pod domain information
First create Pod.
kubectl run nginx --image=nginx:alpine --generator=run-pod/v1
Pod is then exposed Service.
kubectl expose pod nginx --port=8888 --target-port=80 --name=hwcka-004-2-joyo
Service and Pod's Whois Information
[root@svn ch4]# kubectl exec -it busybox -- nslookup hwcka-004-2-joyo
Server: 10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local
Name: hwcka-004-2-joyo
Address 1: 10.110.24.8 hwcka-004-2-joyo.default.svc.cluster.local
[root@svn ch4]# kubectl exec -it busybox -- nslookup nginx
Server: 10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local
Name: nginx
Address 1: ::ffff:67.215.82.154
Address 2: 67.215.82.154
busybox.yaml content (under test environment, not allowed to download nslookup package, but you can pull the mirror, so we use busybox: 1.28 inside the nslookup command)
apiVersion: v1
kind: Pod
metadata:
name: busybox
namespace: default
spec:
containers:
- name: busybox
image: busybox:1.28
command:
- sleep
- "3600"
imagePullPolicy: IfNotPresent
restartPolicy: Always