Goals
- Understand the basics of the deployment and service
- Create our deployment using YAML
- Execute our deployment using YAML
- Verify that the application is working as expected
- Scale the helloworld application
kubectl get deploy/hw -o yaml
. This will return the YAML that composes the helloworld service:localhost:~ xunyang$ kubectl run hw --image=karthequian/helloworld --port=80
deployment.apps "hw" created
localhost:~ xunyang$ kubectl get deployment/hw -o yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: "1"
creationTimestamp: 2018-04-16T04:41:05Z
generation: 1
labels:
run: hw
name: hw
namespace: default
resourceVersion: "11258"
selfLink: /apis/extensions/v1beta1/namespaces/default/deployments/hw
uid: 5f8fbd84-4130-11e8-a846-0800272fd392
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
run: hw
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
run: hw
spec:
containers:
- image: karthequian/helloworld
imagePullPolicy: Always
name: hw
ports:
- containerPort: 80
protocol: TCP
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
status:
availableReplicas: 1
conditions:
- lastTransitionTime: 2018-04-16T04:41:05Z
lastUpdateTime: 2018-04-16T04:41:05Z
message: Deployment has minimum availability.
reason: MinimumReplicasAvailable
status: "True"
type: Available
- lastTransitionTime: 2018-04-16T04:41:05Z
lastUpdateTime: 2018-04-16T04:41:10Z
message: ReplicaSet "hw-596b578c58" has successfully progressed.
reason: NewReplicaSetAvailable
status: "True"
type: Progressing
observedGeneration: 1
readyReplicas: 1
replicas: 1
updatedReplicas: 1
The Kubernetes service also comprises YAML.
run
kubectl get service hw -o yaml
localhost:~ xunyang$ kubectl expose deployment hw --type=NodePort
service "hw" exposed
localhost:~ xunyang$ kubectl get services
NAMETYPECLUSTER-IPEXTERNAL-IPPORT(S)AGE
hwNodePort10.107.135.1480:30764/TCP0s
kubernetesClusterIP10.96.0.1443/TCP19h
localhost:~ xunyang$ kubectl get service hw -o yaml
apiVersion: v1
kind: Service
metadata:
creationTimestamp: 2018-04-16T04:44:21Z
labels:
run: hw
name: hw
namespace: default
resourceVersion: "11471"
selfLink: /api/v1/namespaces/default/services/hw
uid: d4c8b9c5-4130-11e8-a846-0800272fd392
spec:
clusterIP: 10.107.135.14
externalTrafficPolicy: Cluster
ports:
- nodePort: 30764
port: 80
protocol: TCP
targetPort: 80
selector:
run: hw
sessionAffinity: None
type: NodePort
status:
loadBalancer: {}
2 Create our deployment using YAML 【learning|learning kubernetes by minikube, 3】create
helloworld-all.yaml
file, content as belowapiVersion: apps/v1beta1
kind: Deployment
metadata:
name: helloworld-all-deployment
spec:
selector:
matchLabels:
app: helloworld
replicas: 1 # tells deployment to run 1 pods matching the template
template: # create pods using pod definition in this template
metadata:
labels:
app: helloworld
spec:
containers:
- name: helloworld
image: karthequian/helloworld:latest
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: helloworld-all-service
spec:
# if your cluster supports it, uncomment the following to automatically create
# an external load-balanced IP for the frontend service.
type: LoadBalancer
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: helloworld
3 Execute our deployment using YAML
localhost:~ xunyang$ kubectl create -f helloworld-all.yaml
deployment.apps "helloworld-all-deployment" created
service "helloworld-all-service" created
localhost:~ xunyang$ kubectlget all
NAMEREADYSTATUSRESTARTSAGE
helloworld-all-deployment-7c46b4c7dc-2x7561/1Running01sNAMETYPECLUSTER-IPEXTERNAL-IPPORT(S)AGE
helloworld-all-serviceLoadBalancer10.98.124.8280:30100/TCP1s
kubernetesClusterIP10.96.0.1443/TCP1mNAMEDESIREDCURRENTUP-TO-DATEAVAILABLEAGE
helloworld-all-deployment11111sNAMEDESIREDCURRENTREADYAGE
helloworld-all-deployment-7c46b4c7dc1111s
localhost:~ xunyang$
4 Verify that the application is working as expected
localhost:~ xunyang$ kubectl create -f helloworld-all.yaml
deployment.apps "helloworld-all-deployment" created
service "helloworld-all-service" created
localhost:~ xunyang$ kubectlget all
NAMEREADYSTATUSRESTARTSAGE
helloworld-all-deployment-7c46b4c7dc-2x7561/1Running01sNAMETYPECLUSTER-IPEXTERNAL-IPPORT(S)AGE
helloworld-all-serviceLoadBalancer10.98.124.8280:30100/TCP1s
kubernetesClusterIP10.96.0.1443/TCP1mNAMEDESIREDCURRENTUP-TO-DATEAVAILABLEAGE
helloworld-all-deployment11111sNAMEDESIREDCURRENTREADYAGE
helloworld-all-deployment-7c46b4c7dc1111s
localhost:~ xunyang$ minikube service helloworld-all-service
Opening kubernetes service default/helloworld-all-service in default browser...
5 Scale the helloworld application
localhost:~ xunyang$ kubectl get all
NAMEREADYSTATUSRESTARTSAGE
helloworld-all-deployment-7c46b4c7dc-sl9tx0/1ContainerCreating00sNAMETYPECLUSTER-IPEXTERNAL-IPPORT(S)AGE
helloworld-all-serviceLoadBalancer10.110.116.8580:30265/TCP0s
kubernetesClusterIP10.96.0.1443/TCP2mNAMEDESIREDCURRENTUP-TO-DATEAVAILABLEAGE
helloworld-all-deployment11100sNAMEDESIREDCURRENTREADYAGE
helloworld-all-deployment-7c46b4c7dc1100s
localhost:~ xunyang$ kubectl scale --replicas=3 deploy/helloworld-all-deployment
deployment.extensions "helloworld-all-deployment" scaled
localhost:~ xunyang$ kubectl get all
NAMEREADYSTATUSRESTARTSAGE
helloworld-all-deployment-7c46b4c7dc-bzsgv0/1ContainerCreating00s
helloworld-all-deployment-7c46b4c7dc-sl9tx1/1Running015s
helloworld-all-deployment-7c46b4c7dc-vd4h70/1ContainerCreating00sNAMETYPECLUSTER-IPEXTERNAL-IPPORT(S)AGE
helloworld-all-serviceLoadBalancer10.110.116.8580:30265/TCP15s
kubernetesClusterIP10.96.0.1443/TCP2mNAMEDESIREDCURRENTUP-TO-DATEAVAILABLEAGE
helloworld-all-deployment333115sNAMEDESIREDCURRENTREADYAGE
helloworld-all-deployment-7c46b4c7dc33115s
localhost:~ xunyang$ kubectl get all
NAMEREADYSTATUSRESTARTSAGE
helloworld-all-deployment-7c46b4c7dc-bzsgv0/1ContainerCreating03s
helloworld-all-deployment-7c46b4c7dc-sl9tx1/1Running020s
helloworld-all-deployment-7c46b4c7dc-vd4h71/1Running03sNAMETYPECLUSTER-IPEXTERNAL-IPPORT(S)AGE
helloworld-all-serviceLoadBalancer10.110.116.8580:30265/TCP20s
kubernetesClusterIP10.96.0.1443/TCP2mNAMEDESIREDCURRENTUP-TO-DATEAVAILABLEAGE
helloworld-all-deployment333220sNAMEDESIREDCURRENTREADYAGE
helloworld-all-deployment-7c46b4c7dc33220s
localhost:~ xunyang$ kubectl get all
NAMEREADYSTATUSRESTARTSAGE
helloworld-all-deployment-7c46b4c7dc-bzsgv1/1Running08s
helloworld-all-deployment-7c46b4c7dc-sl9tx1/1Running025s
helloworld-all-deployment-7c46b4c7dc-vd4h71/1Running08sNAMETYPECLUSTER-IPEXTERNAL-IPPORT(S)AGE
helloworld-all-serviceLoadBalancer10.110.116.8580:30265/TCP25s
kubernetesClusterIP10.96.0.1443/TCP2mNAMEDESIREDCURRENTUP-TO-DATEAVAILABLEAGE
helloworld-all-deployment333325sNAMEDESIREDCURRENTREADYAGE
helloworld-all-deployment-7c46b4c7dc33325s
6 clear data
localhost:~ xunyang$ kubectl delete deployment --all
deployment.extensions "helloworld-all-deployment" deleted
localhost:~ xunyang$ kubectl delete services --all
service "helloworld-all-service" deleted
service "kubernetes" deleted
localhost:~ xunyang$ kubectlget all
NAMETYPECLUSTER-IPEXTERNAL-IPPORT(S)AGE
kubernetesClusterIP10.96.0.1443/TCP0s
推荐阅读
- 3/100做好简单的事情
- 3/365|3/365 混沌之光
- 3/22-25|3/22-25 ○ 安地斯山的觉醒 ∞ 印加萨满僻静之路 ● 秘鲁 — 霍禾带领
- 3|ELF结构详细分析(1)---elf32_hdr
- 3/70|3/70 细化一月计划