the .yaml file will have the following
apiVersion: (name)
kind: Deployment
metadata:
  name: (appName)
  labels:
    app: (imageTag)
spec:
  replicas: (replicaNumber)
  selector:
    matchLabels:
      app: (imageTag)
  template:
    metadata:
      labels:
        app: (imageTag)
    spec:
      containers:
      - name: (imageTag)
        image: (dockerImage)
        ports:
        - containerPort: (portNumber)
Then enter the following command:
kubectl create -f (.yaml file)
I pulled an example from the edx Kubernetes course using the nginx image to deploy a webserver
I pulled an example from the edx Kubernetes course using the nginx image to deploy a webserver
apiVersion: apps/v1
kind: Deployment
metadata:
  name: webserver
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:alpine
        ports:
        - containerPort: 80
This will deploy an app named webserver replicated across three pods.
We can also define a appName-svc-.yaml file to expose our service with the following content:
apiVersion: (get this value from running kubectl api-version)
kind: Service
metadata:
name: web-service
labels:
run: web-service
spec:
type: (serviceType)
externalName: (externalLink) *Use this field if serviceType is set to ExternalName
ports:
- port: (portNumber)
protocol: TCP
selector:
app: (imageTag)
Then enter the following command:
kubectl create -f (appName)-svc.yaml
serviceType can be any of the below:
apiVersion: v1
kind: Service
metadata:
name: web-service
labels:
run: web-service
spec:
type: NodePort
ports:
- port: 80
protocol: TCP
selector:
app: nginx
This will deploy an app named webserver replicated across three pods.
We can also define a appName-svc-.yaml file to expose our service with the following content:
apiVersion: (get this value from running kubectl api-version)
kind: Service
metadata:
name: web-service
labels:
run: web-service
spec:
type: (serviceType)
externalName: (externalLink) *Use this field if serviceType is set to ExternalName
ports:
- port: (portNumber)
protocol: TCP
selector:
app: (imageTag)
Then enter the following command:
kubectl create -f (appName)-svc.yaml
serviceType can be any of the below:
- LoadBalancer - if the cloud provider Kubernetes is running on provides load balancing.
- ClusterIP - can only reach the service only from within the cluster
- NodePort - creates a ClusterIP and NodePort service will route to it. Allows access from outside the cluster by using NodeIP:NodePort
- ExternalName - maps the service to the contents of the externalName field
apiVersion: v1
kind: Service
metadata:
name: web-service
labels:
run: web-service
spec:
type: NodePort
ports:
- port: 80
protocol: TCP
selector:
app: nginx
 
No comments:
Post a Comment