We are bringing the best of Tectonic to Red Hat OpenShift to build the most secure, hybrid Kubernetes application platform.
This tutorial will deploy a simple, stateless website for a local bakery called "The Cookie Shop" to illustrate how to:
kubectl run
kubectl
Applications may be deployed on Tectonic clusters either by using Tectonic Console or with the kubectl
CLI tool. Likewise, the application can be scaled and monitored either graphically with Console or scriptably on the command line with kubectl
.
This tutorial explores three Kubernetes elements: Deployments, Services, and Ingress.
Begin by logging in to Tectonic Console. Console requires an extra security step of acquiring a one-time token in order to download a kubeconfig
file containing cluster credentials:
https://my-cluster.example.com
Download the kubectl-config
and kubectl
files:
kubectl-config
file.kubectl
binary for your operating system.Move the downloaded kubectl
binary to /usr/local/bin
or another directory on the shell's PATH, and ensure it is executable:
$ chmod +x kubectl
$ mv kubectl /usr/local/bin/kubectl
Make the downloaded kubectl-config
file kubectl’s default configuration by copying it to the ~/.kube
directory:
$ mkdir -p ~/.kube/ # create the directory
$ cp path/to/file/kubectl-config $HOME/.kube/config # rename the file and copy it into the directory
Use kubectl run
with the --expose
option set to create both a Deployment and a Service object with a single command:
$ kubectl run simple-deployment --image=quay.io/coreos/example-app:v1.0 \
--replicas=3 --labels="k8s-app=simple" --port=80 --expose
$ kubectl get svc,deploy
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
svc/kubernetes 10.3.0.1 <none> 443/TCP 2h
svc/simple-deployment 10.3.105.68 <none> 80/TCP 13s
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
deploy/simple-deployment 3 3 3 3 13s
Use kubectl get svc,deploy
to review the running services and deployments just created.
The app is now deployed, but not yet available to a browser interface. To expose the service, use the YAML manifests.
First, use kubectl get
to view the deployment above as a manifest:
$ kubectl get deployment/simple-deployment -o yaml
The output YAML demonstrates that the kubectl run
command created a resource in the cluster (which may be returned as YAML or JSON). These files can be used to create new resources, and may be stored in git, making them easily versionable.
Before continuing, remove the Deployment and Service using kubectl delete
:
$ kubectl delete deployment/simple-deployment,service/simple-service
deployment "simple-deployment" deleted
service "simple-service" deleted
The same application may be deployed using kubectl create
and YAML files.
First, create three YAML files to define the Deployment, Service, and Ingress objects.
Create a file named simple-deployment.yaml
using the YAML content listed below.
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: simple-deployment
namespace: default
labels:
k8s-app: simple
spec:
replicas: 3
selector:
matchLabels:
k8s-app: simple
template:
metadata:
labels:
k8s-app: simple
spec:
containers:
- name: nginx
image: quay.io/coreos/example-app:v1.0
ports:
- name: http
containerPort: 80
The parameter replicas: 3
, will create 3 running copies. Image: quay.io/coreos/example-app:v1.0
defines the container image to run, hosted on Quay.io.
Copy the following into a file named simple-service.yaml
. This file will be used to deploy the service.
kind: Service
apiVersion: v1
metadata:
name: simple-service
namespace: default
spec:
selector:
k8s-app: simple
ports:
- protocol: TCP
port: 80
targetPort: 80
type: ClusterIP
To connect the Service to the containers of the simple-deployment
Deployment, the Service targetPort
and the Deployment containerPort
must match. If targetPort
is not specified, it is assumed to match the external port
. The targetPort
has been specified for clarity in simple-service.yaml
.
Copy the following into a file named simple-ingress.yaml
. This file will be used to create an Ingress resource to act as a local load balancer.
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: simple-ingress
namespace: default
annotations:
kubernetes.io/ingress.class: "tectonic"
ingress.kubernetes.io/rewrite-target: /
ingress.kubernetes.io/ssl-redirect: "true"
ingress.kubernetes.io/use-port-in-redirects: "true"
spec:
rules:
- host: my-cluster.example.com
http:
paths:
- path: /simple-deployment
backend:
serviceName: simple-service
servicePort: 80
To connect the Ingress to the Service, the Ingress's spec.rules.http.paths.backend.serviceName
must match the Service's metadata.name
.
Create the cluster objects specified in the simple-deployment.yaml
, simple-service.yaml
, and simple-ingress.yaml
manifests by passing each file to kubectl create
. Check that the resources were created successfully by listing the objects afterwards:
$ kubectl create -f simple-deployment.yaml
deployment "simple-deployment" created
$ kubectl get deployments
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
deploy/simple-deployment 3 3 3 3 7m
$ kubectl create -f simple-service.yaml
service "simple-service" created
$ kubectl get services -o wide
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
simple-service 10.0.16.4 <pending> 80:30657/TCP 1d k8s-app=simple
$ kubectl create -f simple-ingress.yaml
ingress "simple-ingress" created
$ kubectl get ingress
NAME HOSTS ADDRESS PORTS AGE
simple-ingress my-cluster.example.com 10.0.16.4 80 24s
This deploys three replicas of the application. They'll be connected to by a Service, which is then exposed to the internet by the Ingress resource. Visit https://my-cluster.example.com/simple-deployment/
to confirm the application is up and running.
To deploy using Tectonic Console, copy and paste YAML file content into Tectonic Console to create Deployments, Services, and Ingress.
First, deploy the sample app:
The Console will create your deployment, and display its Overview window.
Then, add the service:
The Console will create the service, and display its Overview window.
Then, add the Ingress resource:
my-cluster.example.com
.The Console will create the Ingress resource, and display its Overview window. Copy the Host and Path and combine them into a URL. Visit https://my-cluster.example.com/simple-deployment
to check your work.
Use Tectonic Console to check the app’s public IP, Service, Deployment, and running Pods.
Go to Routing > Services to monitor the site’s services.
Go to Routing > Ingress and click on the Ingress name to view the Ingress resource.
Go to Workloads > Deployments and click on the Deployment name to display the Deployment’s configuration, manifest YAML, and Pods.