Install Calico on an OpenShift HCP cluster
Big picture
Install Calico on an OpenShift Hosted Control Planes (HCP) cluster.
Value
Provides steps to install Calico in OpenShift Hosted Control Planes (HCP) clusters on AWS. The steps follow the Red Hat procedure for deploying hosted control planes on AWS, with the changes that Calico needs. Calico is on Red Hat's list of certified OpenShift CNI plug-ins, and the listing covers hosted control planes.
How to
Before you begin
-
Ensure that your environment meets the Calico system requirements.
-
Ensure that you have a Red Hat account. You need it to get the pull secret that is required to provision an OpenShift cluster. The OpenShift installer supports a subset of AWS regions.
-
Ensure that you have an AWS account that is configured for OpenShift 4.
-
Install the AWS CLI and configure it with credentials for your AWS account.
Create the hosting cluster
Deploy an OpenShift cluster with Calico. This will be the hosting cluster with control-plane nodes for all hosted clusters you deploy with the steps below. Set up your KUBECONFIG environment variable to your hosting cluster's kubeconfig file:
export KUBECONFIG=/path/to/kubeconfig
Prepare the hosting cluster for hosted control planes
Set up the hosted control planes feature on the hosting cluster and create the AWS resources that hosted clusters need. Red Hat documents each of these steps.
-
Install the multicluster engine for Kubernetes operator, version 2.5 or later, on the hosting cluster. The multicluster engine operator runs the HyperShift operator for you. If the hosted control planes feature is turned off, turn it on.
-
Verify that the
local-clustermanaged cluster exists:oc get managedclusters local-cluster -
Create a routable public zone for the base domain of your hosted clusters.
-
Create an AWS IAM role and STS credentials. You need the role ARN and the
sts-creds.jsonfile when you create the hosted cluster. STS credentials expire, so get new ones if yours have expired. -
Install the
hcpCLI from the hosting cluster:oc get consoleclidownload hcp-cli-download -o jsonpath='{range .spec.links[*]}{.text}{"\t"}{.href}{"\n"}{end}'Download the archive for your platform from a link in the output, then extract the
hcpbinary and add it to yourPATH. For more options, see Installing the hosted control planes command-line interface.
Create a hosted cluster
Create a hosted cluster with no default CNI, so that you can install Calico on it.
- Create a HostedCluster and set its HostedCluster.spec.networking.networkType to Other:
Make sure to adjust the variables for the command below to the correct values for your cluster, credentials and environment.
HOSTED_CLUSTER_NAME=my-os-hosted-cluster
HOSTED_CLUSTER_NS=clusters
REGION=us-west-2
BASE_DOMAIN=www.example.com
PULL_SECRET="$HOME/.secrets/redhat-pull-secret.txt"
STS_CREDS="$HOME/sts-creds.json"
ROLE_ARN="arn:aws:iam::123456789012:role/hcp-cli-role"
hcp create cluster aws \
--name $HOSTED_CLUSTER_NAME \
--infra-id $HOSTED_CLUSTER_NAME \
--namespace $HOSTED_CLUSTER_NS \
--node-pool-replicas 3 \
--base-domain $BASE_DOMAIN \
--pull-secret $PULL_SECRET \
--sts-creds $STS_CREDS \
--role-arn $ROLE_ARN \
--region $REGION \
--generate-ssh \
--network-type Other
Wait until the hosted cluster reports Available:
oc wait --for=condition=Available --timeout=30m -n $HOSTED_CLUSTER_NS hostedcluster/$HOSTED_CLUSTER_NAME
Then use the hcp CLI to generate the kubeconfig file.
Create a separate directory for the hosted cluster, so that you do not mix up configuration and manifests from the hosting and hosted clusters:
mkdir my_hosted_cluster && cd my_hosted_cluster
hcp create kubeconfig --namespace $HOSTED_CLUSTER_NS --name $HOSTED_CLUSTER_NAME > hosted_kubeconfig && export KUBECONFIG=$(pwd)/hosted_kubeconfig
Nodes join the hosted cluster over the next few minutes.
They show as NotReady in oc get nodes until you install Calico.
This is expected.
Then, copy the aws-creds secret from the hosting cluster to the hosted cluster. Run this using the hosting cluster kubeconfig to extract the secret to a yaml file:
oc get secrets --kubeconfig /path/to/hosting/kubeconfig -n kube-system aws-creds -o yaml > aws-creds.yaml
Then import it in the hosted cluster:
oc apply --kubeconfig /path/to/hosted/kubeconfig -f aws-creds.yaml
There is no need to specify the --kubeconfig CLI argument if the hosted cluster's kubeconfig file is configured as the KUBECONFIG environment variable in your shell.
Download the Calico install manifests
Download the Calico manifests for OpenShift:
mkdir calico
wget -qO- https://github.com/projectcalico/calico/releases/download/v3.33.0/ocp.tgz | \
tar xvz --strip-components=1 -C calico
Select and configure a data plane
Calico manifests for OpenShift are ready to configure and install the eBPF data plane. The steps in the eBPF (recommended) tab below will guide you through the process. You can also select a different tab to follow the steps for configuring another data plane.
- eBPF (recommended)
- Iptables
To configure the eBPF data plane, you need to:
Set the
KUBERNETES_SERVICE_HOSTattribute in thecalico/01-configmap-kubernetes-services-endpoint.yamlfile. You can use theoc config viewcommand to look at theserverattribute for the cluster. The following extracts the URL from theoc config viewcommand and sets it.API_SERVER_URL=$(oc config view | sed -n 's/.*server: https:\/\/\([^:]*\).*/\1/p') && \sed -i "s|^\([^:]*KUBERNETES_SERVICE_HOST: \).*\$|\1\"$API_SERVER_URL\"|" calico/01-configmap-kubernetes-services-endpoint.yamlInclude the following
spec.template.spec.dnsConfig.nameserversblock to resolve the apiserver DNS in thecalico/02-tigera-operator.yamlfile. For clusters in AWS, the DNS server address is 169.254.169.253.spec:template:spec:(...)dnsConfig:nameservers:- 169.254.169.253 # AWS DNS serverDisable kube-proxy in the OpenShift Cluster Network Operator:
oc patch network.operator.openshift.io cluster --type merge --patch '{"spec":{"deployKubeProxy":false}}'
To install Calico with iptables, you need to:
Set
linuxDataplanetoIptablesin thecalico/03-cr-installation.yamlfile.Remove the
calico/cluster-network-operator.yamlandcalico/01-configmap-kubernetes-services-endpoint.yamlfiles.
You can do it by running the following command:
sed -i 's/^\(\s*linuxDataplane:\s*\)BPF/\1Iptables/' calico/03-cr-installation.yaml && \
rm -f calico/cluster-network-operator.yaml && \
rm -f calico/01-configmap-kubernetes-services-endpoint.yaml
Optionally provide additional configuration
You may want to provide Calico with additional configuration at install-time. For example, BGP configuration or peers. You can use a Kubernetes ConfigMap with your desired Calico resources to set configuration as part of the installation. If you do not need to provide additional configuration, you can skip this section.
To include Calico resources during installation, edit calico/02-configmap-calico-resources.yaml to add your own configuration.
If you have a directory with the Calico resources, you can create the file with the command:
oc create configmap -n tigera-operator calico-resources \
--from-file=<resource-directory> --dry-run -o yaml \
calico/02-configmap-calico-resources.yaml
With recent versions of oc it is necessary to have a kubeconfig configured or add --server='127.0.0.1:443'
even though it is not used.
If you have provided a calico-resources configmap and the tigera-operator pod fails to come up with Init:CrashLoopBackOff,
check the output of the init-container with oc logs -n tigera-operator -l k8s-app=tigera-operator -c create-initial-resources.
Apply the Calico install manifests
Apply the install manifests paying attention to the required order. First apply all necessary manifests to install the Tigera Operator:
cd calico/
ls 00* | xargs -n1 oc apply -f
ls 01* | xargs -n1 oc apply -f
ls 02* | xargs -n1 oc apply -f
Then wait until the Tigera Operator creates the necessary CustomResourceDefinitions (CRDs) before applying the CustomResources to install Calico on your cluster:
timeout --foreground 600 bash -c "while ! kubectl get crd installations.operator.tigera.io; do sleep 5; done" # wait until CRDs are created by the operator
ls 03* | xargs -n1 oc apply -f
You can safely ignore any ls: cannot access '0X*': No such file or directory errors if there's no yaml files with that prefix to be applied.
Once the above commands are complete, you can verify Calico is installed by verifying the components are available with the following command.
oc get tigerastatus
To get more information, add -o yaml to the above command.
Next steps
Recommended - Networking
- If you are using the default BGP networking with full-mesh node-to-node peering with no encapsulation, go to Configure BGP peering to get traffic flowing between pods.
- If you are unsure about networking options, or want to implement encapsulation (overlay networking), see Determine best networking option.
Recommended - Security
- Secure Calico component communications
- Secure hosts by installing Calico on hosts
- Secure pods with Calico network policy
- If you are using Calico with Istio service mesh, get started here: Enable application layer policy